Skip to content

Clear stale path bytes in install_only tar headers - #1345

Open
RaphaelFakhri wants to merge 1 commit into
astral-sh:mainfrom
RaphaelFakhri:fix-install-only-tar-header-paths
Open

RaphaelFakhri wants to merge 1 commit into
astral-sh:mainfrom
RaphaelFakhri:fix-install-only-tar-header-paths

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Summary

convert_to_install_only rewrites each entry path from python/install/... to python/... with tar::Header::set_path. set_path writes the new path and a NUL terminator but leaves the rest of the 100-byte name field unchanged. It also leaves the ustar prefix field unchanged when the new path fits in name. Each rewritten header kept the tail of the original, longer path after the NUL.

The tar format allows this, but some readers include those bytes in the entry name. For example, older System.Formats.Tar releases in .NET read python/bin/idle3.13 as python/bin/idle3.13\0dle3.13 (dotnet/runtime#117331). In cpython-3.13.16+20261013-x86_64-unknown-linux-gnu-install_only.tar.gz, 4523 of 4526 headers have non-zero bytes after the terminator, for example python/bin/pip\0bin/pip.

This change clears name, and prefix for ustar headers, before calling set_path. The install_only_stripped archives are produced from the install_only archive without changing paths, so they are fixed too.

Fixes #686

Test plan

  • Added release::tests::install_only_clears_stale_header_path_bytes. The test builds a small full archive, converts it, and checks the raw name and prefix bytes of every output header. It covers a short path (bin/idle3.13) and a path stored with a ustar prefix in the input that fits in name after conversion.
  • Without the fix, the test fails on the name check. With only the name clearing, it fails on the prefix check. With the full fix, cargo test --bin pythonbuild passes (4 passed).
  • cargo fmt and cargo clippy --bin pythonbuild --tests report nothing new.

The install_only conversion rewrites each entry path from
python/install/... to python/... with tar::Header::set_path. set_path
does not clear the name field past the new NUL terminator, and does
not clear the ustar prefix when the new path fits in the name field.
Each header kept the tail of the original path after the NUL, which
some tar readers include in the entry name.

Clear the name and prefix fields before setting the new path.

Fixes astral-sh#686

This branch has not been deployed

No deployments
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.

Extra bytes after the null-terminator in the name buffer for tar.gz files

1 participant