Skip to content

Commit

Permalink
Merge pull request #500 from JoostJM/index-overflow
Browse files Browse the repository at this point in the history
BUG: Mitigate integer overflow in texture classes
  • Loading branch information
JoostJM authored Jun 25, 2019
2 parents a68f6cf + 6b6da3e commit 0c23612
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 99 deletions.
4 changes: 2 additions & 2 deletions examples/helloRadiomics.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
extractor.disableAllFeatures()

# Enable all features in firstorder
# extractor.enableFeatureClassByName('firstorder')
extractor.enableFeatureClassByName('glrlm')

# Only enable mean and skewness in firstorder
extractor.enableFeaturesByName(firstorder=['Mean', 'Skewness'])
# extractor.enableFeaturesByName(firstorder=['Mean', 'Skewness'])

print("Calculating features")
featureVector = extractor.execute(imageName, maskName)
Expand Down
20 changes: 10 additions & 10 deletions radiomics/src/_cmatrices.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ static PyObject *cmatrices_calculate_glcm(PyObject *self, PyObject *args)
dims[2] = Ng;
dims[3] = Na;

// Check that the maximum size of the array won't overflow the index variable (int32)
if (dims[0] * dims[1] * dims[2] * dims[3] > INT_MAX)
// Check that the maximum size of the array won't overflow the index variable (size_t)
if (dims[0] * dims[1] * dims[2] * dims[3] > SIZE_MAX)
{
Py_XDECREF(image_arr);
Py_XDECREF(mask_arr);
Expand Down Expand Up @@ -408,8 +408,8 @@ static PyObject *cmatrices_calculate_glszm(PyObject *self, PyObject *args)
dims[1] = Ng;
dims[2] = maxRegion;

// Check that the maximum size of the array won't overflow the index variable (int32)
if (dims[0] * dims[1] * dims[2] > INT_MAX)
// Check that the maximum size of the array won't overflow the index variable (size_t)
if (dims[0] * dims[1] * dims[2] > SIZE_MAX)
{
free(tempData);
PyErr_SetString(PyExc_RuntimeError, "Number of elements in GLSZM would overflow index variable! Increase bin width to prevent this error.");
Expand Down Expand Up @@ -509,8 +509,8 @@ static PyObject *cmatrices_calculate_glrlm(PyObject *self, PyObject *args)
dims[2] = Nr;
dims[3] = Na;

// Check that the maximum size of the array won't overflow the index variable (int32)
if (dims[0] * dims[1] * dims[2] * dims[3] > INT_MAX)
// Check that the maximum size of the array won't overflow the index variable (size_t)
if (dims[0] * dims[1] * dims[2] * dims[3] > SIZE_MAX)
{
Py_XDECREF(image_arr);
Py_XDECREF(mask_arr);
Expand Down Expand Up @@ -661,8 +661,8 @@ static PyObject *cmatrices_calculate_ngtdm(PyObject *self, PyObject *args)
dims[1] = Ng;
dims[2] = 3;

// Check that the maximum size of the array won't overflow the index variable (int32)
if (dims[0] * dims[1] * dims[2] > INT_MAX)
// Check that the maximum size of the array won't overflow the index variable (size_t)
if (dims[0] * dims[1] * dims[2] > SIZE_MAX)
{
Py_XDECREF(image_arr);
Py_XDECREF(mask_arr);
Expand Down Expand Up @@ -814,8 +814,8 @@ static PyObject *cmatrices_calculate_gldm(PyObject *self, PyObject *args)
dims[1] = Ng;
dims[2] = Na * 2 + 1; // No of possible dependency values = Na *2 + 1 (Na angels, 2 directions and +1 for no dependency)

// Check that the maximum size of the array won't overflow the index variable (int32)
if (dims[0] * dims[1] * dims[2] > INT_MAX)
// Check that the maximum size of the array won't overflow the index variable (size_t)
if (dims[0] * dims[1] * dims[2] > SIZE_MAX)
{
Py_XDECREF(image_arr);
Py_XDECREF(mask_arr);
Expand Down
Loading

0 comments on commit 0c23612

Please sign in to comment.