Skip to content

Conversation

@Naveed8951
Copy link

Description

This PR removes undefined behavior in the End Of Central Directory (EOCD)
signature search used when opening ZIP archives.

The previous implementation scanned backward using a pointer-decrement
loop of the form p >= data; p -= 1. When the scan reached the start of
the buffer, the subsequent decrement constructed an out-of-bounds
pointer (data - 1), which is undefined behavior in C. Under hardened
builds or sanitizers, this can result in process aborts.

Changes

  • Replaced the pointer-based backward scan with an index-based scan that
    never constructs pointers outside the allocated buffer
  • Added conservative validation of the scan bounds to ensure last
    remains within the buffer

Impact

  • Eliminates undefined behavior in an untrusted-input parsing path
  • Prevents crashes under UBSan and hardened runtimes
  • Preserves existing EOCD search semantics

Testing

  • Existing regression coverage exercises the non-archive open path
  • Recommended verification:
    • Build with -fsanitize=undefined
    • Run the open-nonarchive regression test to confirm no UB reports

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.

1 participant