Skip to content

Fix float-cast and signed-integer overflow UB in CodedNumericRun. - #887

Merged
copybara-service[bot] merged 1 commit into
mainfrom
test_1026033359
Nov 24, 2026
Merged

copybara-service[bot] merged 1 commit into
mainfrom
test_1026033359

Conversation

@copybara-service

@copybara-service copybara-service Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Fix float-cast and signed-integer overflow UB in CodedNumericRun.

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.

@copybara-service
copybara-service Bot force-pushed the test_1026033359 branch 5 times, most recently from 7bc4885 to 6f56bec Compare November 24, 2026 16:14
`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
copybara-service Bot merged commit 37f7a4c into main Nov 24, 2026
9 checks passed
@copybara-service
copybara-service Bot deleted the test_1026033359 branch November 24, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants