Repository navigation
NAR: the parser and the walk hold archives to upstream's limits - #111
Merged
Merged
Conversation
Upstream's parser reads a keyword with a 32-byte limit, an entry name with 255, a symlink target with 4095, the magic with its own 13 and the executable marker with 0, refusing a longer declared length from its prefix; it refuses an empty target or one holding NUL once read, and a node at depth 64 once its entry's node keyword is read. narStream, narPrefix and deserialise now refuse the same archives at the same points. The walk refuses an entry 64 levels below the root, as upstream's dump does. Every structural string now has a limit of at most 4095 bytes, so the 64 KiB bound never applied: maxWireStringBytes and narStreamBounded go, deserialise drives narStream, and the depth limit is exported as narMaxDepth. The test generators keep symlink targets nonempty and free of NUL, and each limit has cases at and just past it.
aoinoikaz
force-pushed
the
nar/upstream-limits
branch
from
November 28, 2026 01:21
831855c to
433b4c0
Compare
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 NAR parser now refuses what upstream's refuses beyond the grammar: a keyword over 32 bytes, an entry name over 255, a symlink target over 4095, a symlink target that is empty or holds NUL, and a node 64 directories deep. It held every structural string to 64 KiB instead and checked neither targets nor depth, so it accepted archives upstream refuses.
As upstream's
parseDumpdoes, each string is read with its limit (the magic with 13 and the executable marker with 0) and a longer declared length is refused from its prefix, before the bytes it declares are read; an empty target or one holding NUL is refused once read, before the node's); and a node at depth 64, the root at 0, is refused once its entry'snodekeyword is read, before the node's(.narStream,narPrefixanddeserialiseshare one grammar and refuse the same archives at the same points. Each refusal names the string and its limit, or the entry.Upstream's dump refuses a tree that deep as well, so
serialiseFromPathandwithNarSourcerefuse an entry 64 levels below the root with upstream's message,path '<path>' exceeds maximum NAR directory depth of 64, before reading its status. As upstream's dump does, the walk still archives a name past its limit (possible only on Windows, where a name can be 255 UTF-16 units), and that archive does not parse.With every structural string at 4095 bytes or less, the 64 KiB
maxWireStringBytesnever applies, so it andnarStreamBoundedare removed, anddeserialisedrivesnarStreamdirectly;narMaxDepthis exported for the walk. With #110 this is 0.14.0.0. A consumer that relied on the parser accepting these archives fails at run time, not at compile time.The tests cover each limit at and just past it through all three readers, the refusal points (a length refused from its prefix alone, a depth from the
nodekeyword alone, a target before)), and the walk at depths 63 and 64 through both entry points. The property generators keep symlink targets nonempty and free of NUL. The test suite gainsfilepath, with the library's bounds, to name the deep path as the walk renders it.This follows #110 and edits its changelog fragment to drop
narStreamBounded. Verified locally on macOS; Linux and Windows run in CI.