SquashfsHandler: backport 7-Zip 23.00 LzoDecode UInt32 widening (CVE-2023-40481) - #257
Open
tonghuaroot wants to merge 1 commit into
Open
tonghuaroot wants to merge 1 commit into
tonghuaroot wants to merge 1 commit into
Conversation
…2023-40481) Upstream 7-Zip 23.00 changed the `back` offset computation inside LzoDecode() so that the source byte is widened to UInt32 before the shift, preventing a signed-overflow which can cause an out-of-bounds write while extracting a crafted SquashFS image. p7zip carries the pre-fix line and is therefore reachable from the same crafted image. The change is a single-line widening cast equal to upstream 23.00: - back = (b >> 2) + (*src++ << 2); + back = (b >> 2) + ((UInt32)*src++ << 2); The next branch in the same function (mode == 4 path) was already using `((UInt32)src[1] << 6)` in p7zip, so the surrounding code style matches. 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 the one-line UInt32 widening landed in upstream 7-Zip 23.00 to address CVE-2023-40481 (ZDI-23-1164) in the SquashFS handler's LZO decoder.
What changed upstream
7-Zip 23.00 changed
CPP/7zip/Archive/SquashfsHandler.cppinsideLzoDecode()from:to:
Without the cast,
*src++is aBytepromoted toint, and<< 2on the resultingintis performed in signed arithmetic. Together with the subsequent additions, this can compute abackoffset that overflows past the destination buffer, giving an out-of-bounds write while extracting a crafted SquashFS image.p7zip's
LzoDecode()carries the pre-fix expression at line 1047 and inherits the same flaw. The next branch in the same function (mode == 4path) already uses((UInt32)src[1] << 6)in p7zip, so the surrounding code style is consistent with the cast.Patch
Single-line widening, byte-for-byte the same as upstream 23.00:
p7zip has a precedent of backporting CVE fixes one at a time (e.g. #239 for CVE-2021-3520, #254 for the NTFS ClusterSizeLog bound).