Skip to content

Fix undefined shifts in little-endian field parsing - #530

Merged
mtrojnar merged 1 commit into
masterfrom
fix/uint32-shift-ub
Nov 6, 2026
Merged

mtrojnar merged 1 commit into
masterfrom
fix/uint32-shift-ub

Conversation

@mtrojnar

@mtrojnar mtrojnar commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Pull Request Type

  • Bug fix
  • New feature
  • Code style / formatting / renaming
  • Refactoring (no functional or API changes)
  • Build / CI related changes
  • Documentation
  • Other (please describe):

Related Issue

Issue number: N/A

Current Behavior

GET_UINT16_LE/GET_UINT32_LE and the APPX byte readers shift uint8_t values after integer promotion to int. A byte value of 0xFF shifted by 24 overflows int; UBSAN reports undefined behavior and aborts parsing on malformed but otherwise harmless input.

New Behavior

Each byte is cast to uint32_t before shifting, removing the undefined behavior. The parsed values are unchanged for all inputs.

Scope of Changes

Only the little-endian loading macros in osslsigncode.h and the four byte readers in appx.c.

Testing

  • Existing tests
  • New tests added
  • Manual 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

  • I hereby agree to license my contribution under the project's license.

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.
@mtrojnar mtrojnar mentioned this pull request Nov 6, 2026
3 of 11 tasks

@olszomal olszomal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@mtrojnar
mtrojnar merged commit 6356da1 into master Nov 6, 2026
10 checks passed
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.

2 participants