Files
tty7/crates
l0ng-ai f29598af3c harden(kitty): bound the image allocation on its own, not on the check above it
`read_file` refuses a file larger than a frame on its metadata, then reads
through `take` and refuses again on what came back. The second refusal is
what makes the *read* safe, so the first looks like a fast path — and it is,
except for one thing it was also quietly doing: `Vec::with_capacity` was
reserving `meta.len()` verbatim.

`name` arrives in an escape sequence, so that length is an attacker's number
and costs nothing to make enormous — a sparse file is one `set_len`. Between
the two caps, a file that is merely *named* could still ask for its own size
in memory before a byte of it was read. Reserving `min(len, MAX_IMAGE_BYTES)`
makes the bound the allocation's own, so it survives whatever happens to the
check above it.

The new test pins the refusal of an oversized file (sparse, so it costs
nothing) and that a small one is still read. It does not distinguish the two
caps — with the metadata check removed it still passes, because `take` gets
there — and that is said here rather than implied, since the allocation is
the part no test can see.
2026-08-24 02:02:34 +08:00
..