-
Notifications
You must be signed in to change notification settings - Fork 161
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
Fix buffer overflow in TransformationListListNC #3463
Conversation
@james-d-mitchell : I realise this is a busy time of year, just wanted to link you to this in case you had any opinion about it / I'd done anything stupid. |
Codecov Report
@@ Coverage Diff @@
## master #3463 +/- ##
=========================================
Coverage ? 85.34%
=========================================
Files ? 699
Lines ? 346475
Branches ? 0
=========================================
Hits ? 295685
Misses ? 50790
Partials ? 0
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two minor code formatting changes, please.
More importantly, I don't understand why this fixes a buffer overflow. It seems that this change just avoids an unnecessary assignment. So clearly I am missing something. Would you mind giving me a hint? Unless it is super trivial in the end, perhaps there should be a code comment?
woops, done some clang-formatting. The problem (I've tweaked the description to hopefully help) is that at the beginning of the function when we figure out the size of the transformation we need, we basically take the max of the values in the two arrays, EXCEPT we skip any index i where the two lists are equal. This makes sense, because if the transformation maps x to x for any x, we don't need to explicitly store that fact, as that's the default for transformations. Except, if (say) the original arrays were [[1,1000], [2,1000]], we would decide we need a transformation of size 2, but then later try to fill in that the transformation maps 1000 to 1000, just writing into the memory past the end of the transformation. This almost always won't be into another allocated bag (because we've only just allocated this memory), but it will make some future allocated bag be allocated with non-zero values, which is (in practice) basically as bad. |
To save memory, when calculating the size of the transformation, indices where src[i]=ran[i] are skipped. Therefore these same indices must be skipped skipped when filling in the transformation, as we have not allocated memory for them.
also chucked a comment in |
This makes sense to me @ChrisJefferson, well spotted! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, that explanation makes perfect sense.
Fix a buffer overflow in TransformationListList. This bug is in 4.10 (might be in earlier releases too)
Text for release notes