Fix overflow in check_tile_extent() - #1635
Merged
Merged
Conversation
Within `Dimension::check_tile_extent<T>()`, the following variable has a type
deduction from `auto` to `uint64_t`:
auto upper_floor =
((range - 1) / (*tile_extent)) * (*tile_extent) + domain[0];
If `domain[0]` is negative, it may overflow the upper_floor. A trivial example
would be a domain with a range of [-10, -5] with a tile extent size of 5. The
above calculation comes out to -5, which overflows to (MAXINT64 - 5).
If we force the type of `upper_floor` to uint64_t, it solves the above issue
but causes overflow if the tile extent is an unsigned type with a domain
that overflows the uint64_t.
This patch adds both a path for unsigned and signed extent tile types. The
upper_floor type must match the sign of the extent tile type.
This also uncovered a bug in the unit-cppapi-datetimes.cc where the domain
exceeds the expanded upper bound but the check was a false-negative.
stavrospapadopoulos
approved these changes
May 5, 2020
stavrospapadopoulos
left a comment
Member
There was a problem hiding this comment.
Great catch, thanks!
Shelnutt2
pushed a commit
that referenced
this pull request
May 13, 2020
Within `Dimension::check_tile_extent<T>()`, the following variable has a type
deduction from `auto` to `uint64_t`:
auto upper_floor =
((range - 1) / (*tile_extent)) * (*tile_extent) + domain[0];
If `domain[0]` is negative, it may overflow the upper_floor. A trivial example
would be a domain with a range of [-10, -5] with a tile extent size of 5. The
above calculation comes out to -5, which overflows to (MAXINT64 - 5).
If we force the type of `upper_floor` to uint64_t, it solves the above issue
but causes overflow if the tile extent is an unsigned type with a domain
that overflows the uint64_t.
This patch adds both a path for unsigned and signed extent tile types. The
upper_floor type must match the sign of the extent tile type.
This also uncovered a bug in the unit-cppapi-datetimes.cc where the domain
exceeds the expanded upper bound but the check was a false-negative.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Within
Dimension::check_tile_extent<T>(), the following variable has a typededuction from
autotouint64_t:auto upper_floor =
((range - 1) / (*tile_extent)) * (*tile_extent) + domain[0];
If
domain[0]is negative, it may overflow the upper_floor. A trivial examplewould be a domain with a range of [-10, -5] with a tile extent size of 5. The
above calculation comes out to -5, which overflows to (MAXINT64 - 5).
If we force the type of
upper_floorto uint64_t, it solves the above issuebut causes overflow if the tile extent is an unsigned type with a domain
that overflows the uint64_t.
This patch adds both a path for unsigned and signed extent tile types. The
upper_floor type must match the sign of the extent tile type.
This also uncovered a bug in the unit-cppapi-datetimes.cc where the domain
exceeds the expanded upper bound but the check was a false-negative.