Commit Graph
14 Commits
Author SHA1 Message Date
eldritch horrorsandRaito Bezarius 2f7d7444f1 libutil: fix nar parser buffer overflow
string data shares a buffer with the binary string length field. size
calculations for string read buffers always include the length field;
sufficiently large length fields can cause these calculations to wrap.
a malicious nar could use this for OOB writes in the daemon (as root).

since we use strings only as tags for archive members and for symlinks
with their OS-dependent length limits we can simply limit string size.
1 MiB should be sufficient for all symlinks, and tags are always tiny.

Change-Id: I89fb05f73c1dbeda45d91244aba4cd526a3d83e1
2026-05-04 19:00:19 +02:00
Raito Bezarius f8ccd9d572 libutil/async-io: augment read type safety w.r.t to EOFs
Usually, EOFs are represented by returning 0 in the `read` APIs, at
least, this is what read(2) dictate.

As clever creature, we may sum zeroes sometimes (advanced form:
`buf->added(got)`) and forego handling the EOF condition.

To avoid the bug that lurked in remote-store.cc and caused busy looping
if the remote end disconnects suddenly, we return
`Result<Option<size_t>>` forcing the caller to perform a specific
processing for the EOF situation.

The conversion did not raise any other offending code path.

Change-Id: I185fdcb77aa82d87ab0802d66ac37c1363657a73
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-07-23 10:35:37 +00:00
Maximilian Bosch 242a228124 libutil: close file handle in async NAR parser
This bit us while upgrading Hydra[1]: when all the data was read into
the hashing sink while receinving NAR contents, the hash was never
created which lead to a test failing because file size was correct, but
the hash was std::nullopt.

[1] https://git.lix.systems/lix-project/hydra/src/commit/7a0dae579b53b4b96a829263b160c6dc9f42ce75/src/hydra-queue-runner/nar-extractor.cc#L70-L73

Change-Id: Ie71b5f1f17c926a2ab95fb2aabf23c7a575ff70b
2025-06-21 13:52:43 +02:00
eldritch horrors 27d5209f4d libutil: fix copyNAR not reading the whole nar when dropped early
if a copyNAR generator was not drained to completion it would not read
the full nar data from its source. this could happen if the copier was
passed to parseAndDump wrapped as a source because copyNAR would yield
nar metadata *before* it had read it, and GeneratorSource will drain a
generator fully *only* if the source is allowed to throw EndOfFile. in
the parseAndDump case this never happened because parseAndDump expects
to be given an unterminated stream, and thus the combination left some
nar metadata in the input Source, breaking the remote store protocols.

fixes #732

Change-Id: Ia59a53375992bfcdb7bc6b37764ca779622bc8f7
2025-03-18 19:32:58 +00:00
Jade Lovelace b816ae4119 libstore: move case hacking to the FS interaction code
This makes it much harder for bugs to crop up where stuff is wrongly
case hacked.

Fixes the nix store ls problem described in
https://git.lix.systems/lix-project/lix/issues/633, but it is still a
global setting which still sucks.

Fixes: https://git.lix.systems/lix-project/lix/issues/726
Change-Id: Ieba18976d1fb490830db0299ee9922b4b03b453e
2025-03-12 13:42:48 -07:00
eldritch horrors 93c3ca4e92 libutil: fix async copyNAR failing on slow io
well, oops. on slow io (as can happen with ssh remote builders) we could
have extended a nar read buffer past what was actually read, injecting a
span of zeroes into the read buffer where we requested some data but got
a partial result instead. also add some tests that would've caught this.

Change-Id: I67aa06b4715aeec6a5bdacaafa9b79849e664e2f
2025-03-07 15:45:51 +01:00
eldritch horrors 66d515a3a2 libutil: add an async nar indexer
Change-Id: I4c22364c94e2bea1f18b835d9514c4c65a530c80
2025-03-03 20:48:59 +01:00
eldritch horrors 2367521008 libutil: add an async nar parser
sadly this is a visitor-only interface; async generators are not yet a
thing and preliminary benchmarks say that overhead would be too large.

Change-Id: I0460d18eba94441cf3101d46bfffdb69cdda81d1
2025-03-03 20:48:59 +01:00
eldritch horrors 18a24393e8 libutil: add an async copyNAR overload
Change-Id: I046ff704a2d2cb5115f7bf610feac3ed3247d992
2025-03-03 20:48:59 +01:00
eldritch horrors 0d81e81dd1 libutil: add a nar indexer
we'll use this in NarAccessor to provide actually safe indexing of
archives. NarAccessor currently is not fully correct: it relies on
the parser not buffering anything to produce correct file offsets,
but only the nar implementation itself can reasonably expect that.

Change-Id: I64f300b86d8844b876a3ace723546ea7d7b4628b
2025-03-03 20:48:59 +01:00
eldritch horrors 94f15cb5a4 libutil: also test nar copies
Change-Id: Ia57005c476f289c7fbcbf7b96d6aa8e9d403bb86
2025-03-02 16:56:06 +00:00
eldritch horrors 09ada20485 libutil: drop nar metadata variants
like parseAndCopyDump they're no longer needed for anything.

Change-Id: I7e40b9d398a88d4e98cd3e2263315afae057dcbd
2025-02-27 23:51:06 +00:00
eldritch horrors 17e6497ca4 libutil: attach nar member names to dentries, not inodes
this is where they should've been from the start, but during the first
rewrite it made little sense to move them. we have bigger plans today,
so we'll finally clean that up too. note the `Map` transform type that
is needed to make the current macros work. it shall be only temporary.

Change-Id: I928d197dbfe27b68cf8634d149c3259e86fbf123
2025-02-27 23:51:06 +00:00
eldritch horrors 0b4912a0fb libutil: add some c++ nar parser tests
functional2 can't test the actual nar parser library :(

Change-Id: I9f1d8412ba6ed912f74c9edcc2d54216fbda793e
2025-02-27 19:52:44 +00:00