Repository navigation
Fix float-cast and signed-integer overflow UB in CodedNumericRun. - #887
Merged
Merged
Conversation
copybara-service
Bot
force-pushed
the
test_1026033359
branch
5 times, most recently
from
November 24, 2026 16:14
7bc4885 to
6f56bec
Compare
`DecodeIntNumericRun` and `CodedNumericRunIterator<int32_t>` had two undefined-behavior bugs on untrusted `CodedNumericRun` protos:
- `IsInt32(float)` compared `number <= static_cast<float>(INT32_MAX)`. Because `INT32_MAX` (`2^31 - 1`) rounds up to `2^31` (`2147483648.0f`) in IEEE-754 float, `2147483648.0f` passed the range check and triggered `float-cast-overflow` when cast to `int32_t`.
- `CodedNumericRunIterator<int32_t>::UpdateDeltaAndValue` computed `static_cast<int64_t>(run_->offset()) + static_cast<int64_t>(run_->scale()) * cumulative_delta_` directly in `int64_t`, overflowing signed `int64_t` in as few as three deltas when `scale` and `cumulative_delta_` are large, and narrowing out-of-range values into `int32_t`.
Reject floats `>= static_cast<float>(INT32_MAX)` with a strict `<` check in `IsInt32`, validate in `DecodeIntNumericRun` that every decoded value lies within `int32_t` bounds (returning `InvalidArgumentError` on overflow instead of wrapping or clamping), and iterate decoded ranges in the `Decode{Int,Float}NumericRun` fuzz tests so iterator dereferencing is exercised continuously.
PiperOrigin-RevId: 1029069205
copybara-service
Bot
force-pushed
the
test_1026033359
branch
from
November 24, 2026 16:21
6f56bec to
37f7a4c
Compare
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.
Fix float-cast and signed-integer overflow UB in CodedNumericRun.
DecodeIntNumericRunandCodedNumericRunIterator<int32_t>had two undefined-behavior bugs on untrustedCodedNumericRunprotos:IsInt32(float)comparednumber <= static_cast<float>(INT32_MAX). BecauseINT32_MAX(2^31 - 1) rounds up to2^31(2147483648.0f) in IEEE-754 float,2147483648.0fpassed the range check and triggeredfloat-cast-overflowwhen cast toint32_t.CodedNumericRunIterator<int32_t>::UpdateDeltaAndValuecomputedstatic_cast<int64_t>(run_->offset()) + static_cast<int64_t>(run_->scale()) * cumulative_delta_directly inint64_t, overflowing signedint64_tin as few as three deltas whenscaleandcumulative_delta_are large, and narrowing out-of-range values intoint32_t.Reject floats
>= static_cast<float>(INT32_MAX)with a strict<check inIsInt32, validate inDecodeIntNumericRunthat every decoded value lies withinint32_tbounds (returningInvalidArgumentErroron overflow instead of wrapping or clamping), and iterate decoded ranges in theDecode{Int,Float}NumericRunfuzz tests so iterator dereferencing is exercised continuously.