test: add trailing-slash corner-case#187
Closed
rmg wants to merge 1 commit intoisaacs:masterfrom
Closed
Conversation
The logic for checking if an entry is marked as a file but has a trailing '/' in the path trips over files that happen to be under a 99-character path that is the perfect length for the 100-byte truncated path to _look_ like it is has a trailing / when it really doesn't. ``` <1: header, link, "././@LongLink"> <2: "full-path-to-file-inside-dir/filename"> <3: header, file, "first-99-bytes-of-full-path/"> <4: body of file> ``` The parser appears to treat the above as: 1. parse link entry as normal 2. parse metadata frame 3. parse file entry as directory entry 4. assume next frame is next entry This happens with tarballs generated by GNU Tar, but it is **not** related to the `gnu` tar format. The way BSD tar generates the above is: ``` <frame: header, file, "path-after-the-slash", prefix> <frame: body of file> ``` It appears that the root cause is GNU Tar doesn't use the prefix field of the POSIX tar header and instead relies on the link frame and assumes that the path in the following "real" file entry is mostly advisory so it doesn't matter that it is truncated at 100 bytes. BSD Tar, on the other hand, makes use of the prefix field and instead only puts the file portion of the path in the path field. The take away here is that if you are not using npm to tar up your bundles, at least use BSD Tar instead of GNU Tar, because even after fixing this there will be a long tail of broken versions of npm to support.
Contributor
Author
|
@isaacs this is the reduced test case I was describing to you |
Contributor
Author
|
Here's some hex-dumps of the troublesome tarball: https://gist.github.com/rmg/922ce5256e535a77682d19037e8fa622 |
Owner
|
Thank you! I'll take a look soon. |
This was referenced Nov 5, 2025
This was referenced Nov 27, 2025
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.
The logic for checking if an entry is marked as a file but has a
trailing '/' in the path trips over files that happen to be under a
99-character path that is the perfect length for the 100-byte truncated
path to look like it is has a trailing / when it really doesn't.
The parser appears to treat the above as:
This happens with tarballs generated by GNU Tar, but it is not
related to the
gnutar format.The way BSD tar generates the above is:
It appears that the root cause is GNU Tar doesn't use the prefix field
of the POSIX tar header and instead relies on the link frame and assumes
that the path in the following "real" file entry is mostly advisory so
it doesn't matter that it is truncated at 100 bytes.
BSD Tar, on the other hand, makes use of the prefix field and instead
only puts the file portion of the path in the path field.
The take away here is that if you are not using npm to tar up your
bundles, at least use BSD Tar instead of GNU Tar, because even after
fixing this there will be a long tail of broken versions of npm to
support.