StdOutStream: backport 7-Zip 26.01 terminal escape filter - #260
Open
tonghuaroot wants to merge 1 commit into
Open
tonghuaroot wants to merge 1 commit into
tonghuaroot wants to merge 1 commit into
Conversation
Upstream 7-Zip 26.01 (released 2026-04-27) replaced the narrow
"\a \b \t \n \v \f \r" filter in CStdOutStream::Normalize_UString
with a comprehensive IsDangerousTerminalChar() that also covers:
- all of the C0 controls (0x00..0x1F), including ESC (0x1b)
- DEL (0x7F) and the C1 controls (0x80..0x9F), including the 0x9B
8-bit CSI byte that terminals treat as start-of-escape-sequence
- Unicode BiDi override characters 0x202A..0x202E (LRE/RLE/PDF/LRO/RLO)
and 0x2066..0x2069 (LRI/RLI/FSI/PDI), the "Trojan Source" family.
p7zip's pre-existing filter was even narrower than upstream 26.00 --
it covered c >= 7 && c <= 13 but lacked ESC (0x1b). With only those
bytes filtered, an attacker who supplies an archive can embed BiDi
override codepoints in an entry name (which the listing path prints
verbatim) so that the displayed name disagrees with the on-disk name --
e.g. a file shown as "safe.txt" but actually written as "exe.tnp".
Similarly the 0x9B CSI byte was not filtered, allowing an archive name
to inject raw ANSI escape sequences into the user's terminal when
running 7z l / 7z x.
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 the terminal escape filter expansion landed in upstream 7-Zip 26.01 (released 2026-04-27) to keep parity with mainline on
CStdOutStream::Normalize_UString.What changed upstream
CPP/Common/StdOutStream.cppin p7zip filters only\a \b \t \v \f \r(c >= 7 && c <= 13) when printing strings sourced from archives (entry names, error / warning messages) to the user's terminal. p7zip's filter is even narrower than 7-Zip 26.00 -- it lacks ESC (0x1b).7-Zip 26.01 replaces the narrow check with
IsDangerousTerminalChar()which also filters:0x00..0x1F, including ESC0x7F) and the C1 control range0x80..0x9F, including0x9Bwhich terminals treat as the 8-bit CSI start-of-escape byte0x202A..0x202E(LRE/RLE/PDF/LRO/RLO) and0x2066..0x2069(LRI/RLI/FSI/PDI), the "Trojan Source" familyImpact
Archive entry names are attacker-controlled UTF-16 strings printed verbatim by
7z land during7z x. With onlyc >= 7 && c <= 13filtered, an archive can:0x1b(ESC) or0x9Bfollowed by ANSI sequences to overwrite earlier terminal output.Patch
The hunk matches the upstream 7-Zip 26.01 source.
Normalize_UString_Pathreaches the same code path throughNormalize_UString, so callers that print paths during list/extract get the fix transparently.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.