Repository navigation
NAR: narPrefix parses a NAR that more input follows - #110
Merged
Merged
Conversation
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.
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.
NovaCache.NAR.StreamgainsnarPrefix, 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.narStreamfails 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
parseDumpdoes, 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" errornarStreamgives. 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.NarStepgains a type parameter for the resultNarDonecarries:()fromnarStreamandnarStreamBounded, the bytes after the archive fromnarPrefix. The two share one grammar. This breaks the API under the PVP, so the next release is 0.14.0.0; a consumer that matchesNarDonenow matchesNarDone (). The server parses no NAR (neither its modules nor the executable importNovaCache.NARorNovaCache.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,
narPrefixyields the eventsnarStreamyields for the archive alone and hands back exactly the trailing bytes, without awaiting more input; every strict prefix of an archive fails as truncated; andnarStreamrefuses 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.