Avoid signed overflow in AndroidZoneInfoSource::Open offset math#360
Closed
ravi0800 wants to merge 1 commit into
Closed
Avoid signed overflow in AndroidZoneInfoSource::Open offset math#360ravi0800 wants to merge 1 commit into
ravi0800 wants to merge 1 commit into
Conversation
devbww
reviewed
Jul 23, 2026
Comment on lines
-536
to
+537
| const std::int_fast32_t start = data_offset + Decode32(ebuf + 40); | ||
| const std::int_fast64_t start = | ||
| std::int_fast64_t{data_offset} + Decode32(ebuf + 40); |
Contributor
There was a problem hiding this comment.
This looks like it is being handled in #356. Please take a look there and see if you have anything to add. Otherwise we can close this PR. Thanks.
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.
AndroidZoneInfoSource::Open() computes a zone's file position as data_offset + Decode32(ebuf + 40), where both operands are int_fast32_t values pulled straight from the tzdata index. On a build where int_fast32_t is a 32-bit type (32-bit Android/ARM), two near-INT_MAX index values sum past the type's range, so the addition is signed overflow before the start < 0 guard on the next line ever runs. UBSan on a crafted tzdata blob reports "signed integer overflow: 76 + 2147483647 cannot be represented in type int" right at that add.
Widen the left operand to int_fast64_t so the sum is formed in a type that holds it, which leaves the existing start < 0 / length < 0 rejection meaningful and the later static_cast(start) for fseek unchanged. Doing the widening at the add keeps the fix inside the decode where the operand widths are still in view.