Skip to content

parse: Truncate GNU LongName/LongLink content at the first NUL byte#28

Merged
cgwalters merged 2 commits into
composefs:mainfrom
cgwalters:nul-trim
May 19, 2026
Merged

parse: Truncate GNU LongName/LongLink content at the first NUL byte#28
cgwalters merged 2 commits into
composefs:mainfrom
cgwalters:nul-trim

Conversation

@cgwalters
Copy link
Copy Markdown
Collaborator

The GNU tar format specifies that LongName and LongLink content is a NUL-terminated C string. The previous code only stripped a single trailing NUL, which could cause confusion for callers because in practice filenames can't have embedded NUL bytes.

GNU tar, Python tarfile, and Go archive/tar all truncate at the first NUL.

Assisted-by: OpenCode (Claude Sonnet 4.6)

cgwalters added 2 commits May 19, 2026 14:51
The GNU tar format specifies that LongName and LongLink content is a
NUL-terminated C string.  The previous code only stripped a single
trailing NUL, which could cause confusion for callers because
in practice filenames can't have embedded NUL bytes.

GNU tar, Python tarfile, and Go archive/tar all truncate at the first
NUL.

Assisted-by: OpenCode (Claude Sonnet 4.6)
Signed-off-by: Colin Walters <walters@verbum.org>
…harness

tar-core now truncates the resolved path/link-target at the first NUL
byte for GNU LongName/LongLink headers, matching GNU tar's C-string
convention (commit 92ea76d). tar-rs does not perform this truncation,
so the cargo-fuzz differential harness was failing on any archive where
the GNU long-name/link content contains an embedded NUL.

The fix is in the testutil's parse_tar_rs function: normalize path and
link_target by truncating at the first NUL before comparison. This is
the same logic tar-core applies, so both sides now represent the same
semantically correct value. The differential.rs module doc is updated to
document this as an allowlisted behavioral difference.

Assisted-by: OpenCode (Claude Sonnet 4.6)
Signed-off-by: Colin Walters <walters@verbum.org>
@cgwalters cgwalters merged commit 6d27e13 into composefs:main May 19, 2026
5 checks passed
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.

1 participant