Use checked arithmetic for TZif data block lengths - #1812
Open
n0liu wants to merge 1 commit into
Open
Conversation
The TZif parser computes several data block lengths by multiplying counts taken straight from the untrusted header (transition_count * time_size, type_count * 6, leap_count * (time_size + 4)). A malformed header with a huge count overflows the usize multiplication, which panics on 32-bit targets. Use checked_mul and return an error instead. Addresses the TZif parser finding in chronotope#1802.
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.
Addresses the TZif parser finding in #1802.
State::newin the TZif parser computes several data-block lengths by multiplying counts taken straight from the (untrusted) header —transition_count * time_size,type_count * 6,leap_count * (time_size + 4). A malformed header with a huge count overflows theusizemultiplication, which panics on 32-bit targets. (On 64-bit the product still fits, and the oversizedread_exactfails cleanly, so the panic is 32-bit only.)Compute those lengths with
checked_muland returnError::InvalidTzFileon overflow, so a malformed header is rejected instead of panicking.Added a test that feeds a header with
type_count = u32::MAXand asserts parsing returns an error. Full test suite,cargo fmt, andclippy -D warningspass.