fix undefined behavior in EOCD backward scan
## 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
合并状态:未合并 关闭于 2026-02-17 3 条评论