Skip to content

fix(report): keep finding zip names on a rune boundary - #322

Merged
BaaRai merged 1 commit into
BaaRai:mainfrom
Dev-next-gen:fix/finding-filename-utf8
Nov 18, 2026
Merged

BaaRai merged 1 commit into
BaaRai:mainfrom
Dev-next-gen:fix/finding-filename-utf8

Conversation

@Dev-next-gen

Copy link
Copy Markdown
Contributor

Exporting findings as a Markdown zip garbles the file name of any finding whose name is long and not ASCII. With a finding named 用户资料页面个人简介富文本编辑器存在存储型跨站脚本漏洞可窃取管理员会话令牌并接管账户 (severity high), the zip entry is listed by unzip/Python's zipfile as high_τö¿µê╖Φ╡äµûÖ…µ.md.

FindingFilename caps the name at 120 bytes with name[:120], which can cut a multi-byte character in half (here the name ends in a stray \xe8). archive/zip only sets the UTF-8 flag (general purpose bit 11) when the entry name is valid UTF-8, so the entry is written without it and readers fall back to CP437 for the whole name, not just the last character. Names that fit in 120 bytes are unaffected, which is why short Chinese names export fine.

The fix drops the trailing partial character after the cut with strings.ToValidUTF8, so the name stays valid UTF-8 and at most 120 bytes.

I added TestFindingsZipLongNonASCIINameStaysUTF8, which builds the archive through writeFindingsEvidenceZip (what the md-zip export serves) and reads the entry back. Before the fix it fails with NonUTF8=true and the name ending in \xe8; after it passes, and the exported entry reads back as high_用户资料页面…令牌并.md with flag 0x808. go test ./report still passes.

Found by a defect-hunting pipeline I build and run (Dev-next-gen), using Claude Code with Anthropic's Claude Opus 5.5.

FindingFilename cut the name at 120 bytes, which can split a multi-byte
character. archive/zip only sets the UTF-8 flag on valid names, so the
entry was written without it and unzip tools decoded the whole name as
CP437, garbling every non-ASCII character in it.

@BaaRai BaaRai left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cut now lands on a rune boundary, and the test asserts the zip writer keeps the UTF-8 flag, which is the actual failure: one invalid byte makes readers decode the whole name as CP437. Thanks.

@BaaRai
BaaRai merged commit 366e140 into BaaRai:main Nov 18, 2026
6 checks passed
@shantidevi876422-beep

Copy link
Copy Markdown

sha256:ed07d43bbd92b95476859ab02c670ca765e8ba56d5e26731067aa95b1d477397

1 similar comment
@shantidevi876422-beep

Copy link
Copy Markdown

sha256:ed07d43bbd92b95476859ab02c670ca765e8ba56d5e26731067aa95b1d477397

@shantidevi876422-beep

Copy link
Copy Markdown

__

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants