mirror of
https://github.com/l0ng-ai/tty7.git
synced 2026-09-22 08:02:24 +00:00
`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.