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

exrcheck: use 64 bit integer math to prevent pointer overflows #930

Conversation

peterhillman
Copy link
Contributor

Address issues:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=31221
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=31228
(also, all example images read through exrcheck when compiled with the undefined behavior sanitizer)

exrcheck had the usual thorny bugs handling images with massively offset data windows. Where dataWindow.min.{x,y} are very large or very negative, 32 bit integer arithmetic overflows and/or negative pointer arithmetic occurred.

Signed-off-by: Peter Hillman peterh@wetafx.co.nz

Signed-off-by: Peter Hillman <peterh@wetafx.co.nz>
@@ -521,9 +529,14 @@ readDeepTile(T& in,bool reduceMemory , bool reduceTime)

DeepFrameBuffer frameBuffer;

int memOffset = dataWindow.min.x + dataWindow.min.y * width;
//
// use 64 bit integer arithmetic instead of pointer arithmetic to compute offset into array. Pointer arithmetic may overflow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest amending the comment to 'pointer arithmetic may overflow on 32 bit architectures'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have amended accordingly. I think this is architecture dependent, and more to do with the size of ints.
The value of 'memOffset' needs to be computed with 64 bit arithmetic. For example, if dataWindow.min.y*width is greater than 2^31 and dataWindow.min.x is very negative, the end result should be a relatively small number.
Also, I think memOffset needs to be 64 bits on a 64 bit architecture.

Signed-off-by: Peter Hillman <peterh@wetafx.co.nz>
@peterhillman peterhillman merged commit 2f01a25 into AcademySoftwareFoundation:master Feb 22, 2021
@peterhillman peterhillman deleted the exrcheck_pointer_overflow branch February 22, 2021 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants