Repository navigation
Fix undefined shifts in little-endian field parsing - #530
Merged
Merged
Conversation
GET_UINT16_LE/GET_UINT32_LE and the APPX byte readers shift uint8_t values after integer promotion to int. A 0xFF byte shifted by 24 overflows int, which UBSAN reports as undefined behavior and aborts the parser on malformed but otherwise harmless input. Cast each byte to uint32_t before shifting.
3 of 11 tasks
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.
Pull Request Type
Related Issue
Issue number: N/A
Current Behavior
GET_UINT16_LE/GET_UINT32_LEand the APPX byte readers shiftuint8_tvalues after integer promotion toint. A byte value of0xFFshifted by 24 overflowsint; UBSAN reports undefined behavior and aborts parsing on malformed but otherwise harmless input.New Behavior
Each byte is cast to
uint32_tbefore shifting, removing the undefined behavior. The parsed values are unchanged for all inputs.Scope of Changes
Only the little-endian loading macros in
osslsigncode.hand the four byte readers inappx.c.Testing
Built with ASAN+UBSAN and ran malformed CAB/PE/MSI/APPX reproducers that previously reported
left shift ... cannot be represented in type 'int'; they now complete without a sanitizer report.Additional Notes
This is undefined behavior, not memory corruption. It was surfaced by the fuzzing campaigns after UBSAN was enabled.
License Declaration