Skip to content

NAR: the parser and the walk hold archives to upstream's limits - #111

Merged
aoinoikaz merged 1 commit into
mainfrom
nar/upstream-limits
Nov 28, 2026
Merged

aoinoikaz merged 1 commit into
mainfrom
nar/upstream-limits

Conversation

@aoinoikaz

@aoinoikaz aoinoikaz commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

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 parseDump does, 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's node keyword is read, before the node's (. narStream, narPrefix and deserialise share 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 serialiseFromPath and withNarSource refuse 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 maxWireStringBytes never applies, so it and narStreamBounded are removed, and deserialise drives narStream directly; narMaxDepth is 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 node keyword 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 gains filepath, 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.

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
aoinoikaz merged commit 41ffaa7 into main Nov 28, 2026
12 checks passed
@aoinoikaz
aoinoikaz deleted the nar/upstream-limits branch November 28, 2026 01:43
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