Repository navigation
🐞 Revert LibZip.flzDecompress on a truncated FastLZ instruction - #1566
gomesalexandre wants to merge 6 commits into
Conversation
Incomplete literal and match headers were decoded by reading past the payload, so callers received a short zero-padded bytes string. Those inputs now revert with TruncatedFastLZ. Co-authored-by: Cursor <cursoragent@cursor.com>
The Osaka copy walks FastLZ the same way as src/utils/LibZip.sol, so a short instruction still returned zero padding there. Co-authored-by: Cursor <cursoragent@cursor.com>
A payload that ends on the 0x00 marker loaded the missing control byte from past the end and appended a run of zeros or 0xff. That marker is now left unexpanded. Co-authored-by: Cursor <cursoragent@cursor.com>
The Osaka copy read the missing control byte from past the payload, same as src/utils/LibZip.sol. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Follow-up on this branch, commits 983d362 and 9f5831b.
|
Calldata that ends on the 0x00 marker loaded the missing control byte from past the end and appended a run. That marker is now left unexpanded. Co-authored-by: Cursor <cursoragent@cursor.com>
The Osaka copy loaded the missing control byte from past calldata, same as src/utils/LibZip.sol. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Follow-up on this branch, commits a773fbd and 9951036.
|
|
@gomesalexandre Thanks for the PR and the detailed repros! After some marinating, I think it's better to leave the decompress functions as they are.
If someone needs to handle untrusted compressed data, checking a hash of the decompressed result on their end is cheaper than making everyone pay. I think a note in the natspec is enough here: the input is assumed to be valid and is not validated. Happy to see this trimmed down to just the notes. |
Description
LibZip.flzDecompresstreated a FastLZ control byte inside the buffer as a complete instruction. The rest of the instruction was read withmload, so bytes past the payload were the zero padding after thebytesallocation. A truncated literal or match came back as a successful short string.On
mainat258f67cc, a forge probe against the unfixed function returnedhex"00"for payloadhex"00"(one literal byte, none present) andhex"410000"for payloadhex"0241"(three literal bytes, only0x41present). The same inputs now revert withTruncatedFastLZ()(0x8bb83a49).The check matches the byte count the old loop already advanced: a literal of control
cisc + 2bytes, a short match is 2, and a long match (t == 7) is 3. A stream that ends exactly on an instruction boundary still decodes. Empty input still returns empty. The Osaka copy insrc/utils/clz/LibZip.solhad the same walk, so it now reverts the same way. That file compiles with solc 0.8.36 at--evm-version osaka.Checklist
forge fmt?forge test?FOUNDRY_DISABLE_NIGHTLY_WARNING=1 forge test --match-contract LibZipTest --no-match-path 'test/clz/*'on the fixed tree: 31 passed, 0 failed, includingtestFlzDecompressTruncatedRevertsand the 256-runtestFlzCompressDecompress(bytes)round trip.Made with Cursor