Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Mitigate integer overflow in texture classes #500

Merged
merged 2 commits into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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