SquashfsHandler: backport 7-Zip 26.01 ReadBlock bounds-check hardening - #262
Open
tonghuaroot wants to merge 1 commit into
Open
SquashfsHandler: backport 7-Zip 26.01 ReadBlock bounds-check hardening#262tonghuaroot wants to merge 1 commit into
tonghuaroot wants to merge 1 commit into
Conversation
Upstream 7-Zip 26.01 (released 2026-04-27) hardened
CHandler::ReadBlock() against two attacker-influenced inputs in
malformed SquashFS images:
1. The bounds check before the final memcpy was
if (offsetInBlock + blockSize > _cachedUnpackBlockSize)
which can wrap when offsetInBlock + blockSize overflows UInt32.
26.01 rewrites it in overflow-safe subtractive form:
if (_cachedUnpackBlockSize < offsetInBlock ||
_cachedUnpackBlockSize - offsetInBlock < blockSize)
2. For fragmented file inodes, `offsetInBlock = node.Offset` is taken
directly from inode metadata. 26.01 adds a sanity check that
`offsetInBlock <= _h.BlockSize` before proceeding, so an inode
that claims an offset beyond the block size is rejected up-front.
Patch matches upstream 7-Zip 26.01 source.
Signed-off-by: tonghuaroot <tonghuaroot@gmail.com>
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.
Backports two
CHandler::ReadBlock()hardenings landed in upstream 7-Zip 26.01 (released 2026-04-27).What changed upstream
The bound just before the final
memcpy(dest, _cachedBlock + offsetInBlock, blockSize)was```cpp
if (offsetInBlock + blockSize > _cachedUnpackBlockSize)
return S_FALSE;
```
which is overflow-prone if
offsetInBlock + blockSizewraps a 32-bit add. 26.01 rewrites it in overflow-safe subtractive form:```cpp
if (_cachedUnpackBlockSize < offsetInBlock ||
_cachedUnpackBlockSize - offsetInBlock < blockSize)
return S_FALSE;
```
For fragmented file inodes,
offsetInBlock = node.Offsetis taken directly from inode metadata. 26.01 adds a sanity checkoffsetInBlock <= _h.BlockSizeimmediately afterwards so an inode that claims an offset beyond a block is rejected up-front.Impact
A crafted SquashFS image with attacker-controlled
node.Offsetnear0xFFFFFFFFcombined with a smallblockSizecan wrapoffsetInBlock + blockSizebelow_cachedUnpackBlockSizeand pass the check, after which thememcpyperforms a length-controlled OOB read past_cachedBlockand writes the bytes into the caller'sdestbuffer.Patch
Two small hunks, byte-for-byte matching upstream 26.01.
Disclosure
I am not a native English speaker. AI tooling was used to polish the prose in this PR description. The fix itself is a direct backport from upstream 7-Zip 26.01 source; no design choices were made beyond matching upstream verbatim.