Fix signed integer overflow in gzseek64 SEEK_SET normalization (UBSan)#1245
Open
XananasX7 wants to merge 1 commit into
Open
Fix signed integer overflow in gzseek64 SEEK_SET normalization (UBSan)#1245XananasX7 wants to merge 1 commit into
XananasX7 wants to merge 1 commit into
Conversation
|
@madler: Have you seen this security PR? Linked to: |
0dd06d2 to
46e6eec
Compare
Author
|
Friendly ping on this fix for the signed integer overflow in |
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.
Summary
Fix a signed integer overflow (undefined behavior) in
gzseek64()when normalizing aSEEK_SEToffset.Root Cause
gzlib.cline 389:offsetandstate->x.posare bothz_off64_t(signed 64-bit). When the caller passesoffset == INT64_MIN(-9223372036854775808) and the stream has advanced at least one byte (state->x.pos > 0), the subtraction overflows the signed type — undefined behavior per C11 §6.5p5, and flagged by UBSan asruntime error: signed integer overflow.The intended error path (checking
offset < 0after normalization) is never reached because the overflow wraps to a large positive value, bypassing the bounds check entirely.Fix
Add an explicit overflow guard before the subtraction:
This preserves all existing semantics for valid offsets and turns the UB into a clean error return.
Fixes #1222.