Skip to content

NAR: narPrefix parses a NAR that more input follows - #110

Merged
aoinoikaz merged 1 commit into
mainfrom
nar/stop-at-root-close
Nov 28, 2026
Merged

aoinoikaz merged 1 commit into
mainfrom
nar/stop-at-root-close

Conversation

@aoinoikaz

Copy link
Copy Markdown
Contributor

NovaCache.NAR.Stream gains narPrefix, a parser for a NAR at the front of a longer input. It finishes at the root node's close, without awaiting more input, with the bytes after that close. narStream fails on any byte after the root node, so a NAR inside a stream that goes on past it could not be parsed without knowing its length first. The nova-nix daemon (Novavero-AI/nova-nix#512) reads NARs this way: the worker protocol sends path infos and NARs back to back in one framed stream.

As upstream's parseDump does, it reads exactly the archive, through the root node's ) and its padding, and an input that ends before that close fails, here with the "unexpected end of NAR" error narStream gives. The bytes it finishes with are a suffix of the last chunk fed, so a caller knows which bytes were the archive, for its hash and size.

NarStep gains a type parameter for the result NarDone carries: () from narStream and narStreamBounded, the bytes after the archive from narPrefix. The two share one grammar. This breaks the API under the PVP, so the next release is 0.14.0.0; a consumer that matches NarDone now matches NarDone (). The server parses no NAR (neither its modules nor the executable import NovaCache.NAR or NovaCache.NAR.Stream), so its behaviour does not change.

The tests generate NAR trees (files with and without the executable flag, contents on and off the 8-byte alignment, symlinks, nested and empty directories), trailing bytes (none, arbitrary, another archive) and chunkings of mostly 1 to 9 bytes, so lengths and padding straddle chunk boundaries. Over them, narPrefix yields the events narStream yields for the archive alone and hands back exactly the trailing bytes, without awaiting more input; every strict prefix of an archive fails as truncated; and narStream refuses an archive with any byte after it.

Upstream's parser refuses some archives the shared node parsing accepts (directories nested 64 deep, tokens over 32 bytes, names over 255 bytes and symlink targets over 4095, an empty symlink target or one holding NUL). This change leaves those as they are.

narPrefix finishes at the root node's close, without awaiting more
input, with the bytes after that close, as upstream's parseDump reads a
NAR from a stream and leaves what follows to the stream's next reader.
narStream fails on any byte after the root node, so a NAR inside a
stream that goes on past it could not be parsed without knowing its
length first.

NarStep takes the type of the result NarDone carries: () from
narStream and narStreamBounded, the bytes after the archive from
narPrefix. The node parsers are polymorphic in it, so both machines
share one grammar.

QuickCheck properties over generated trees, trailing bytes and
chunkings pin the prefix parse against narStream's events, the bytes it
hands back, that it never awaits the end of input, and that an archive
cut short fails as truncated.
@aoinoikaz
aoinoikaz merged commit 15fb179 into main Nov 28, 2026
12 checks passed
@aoinoikaz
aoinoikaz deleted the nar/stop-at-root-close branch November 28, 2026 01:21
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