Skip to content

cli: -l reports a frame cut short as truncated - #5089

Open
burrows99 wants to merge 1 commit into
meta:devfrom
burrows99:fix/list-truncated-checked-frame
Open

burrows99 wants to merge 1 commit into
meta:devfrom
burrows99:fix/list-truncated-checked-frame

Conversation

@burrows99

Copy link
Copy Markdown

What and why

zstd -l only reports a file as truncated when the frame has no checksum and the cut falls inside block data. The CLI writes a checksum by default, so a normal .zst cut short anywhere (in the frame header, a block header, a block, or before the checksum) is reported as a parse error instead, followed by a table row with 0 frames, the full declared uncompressed size and a ratio computed from it. That row also goes into the total:

$ zstd -q notes.txt
$ head -c 20000 notes.txt.zst > cut.zst
$ zstd -l notes.txt.zst cut.zst
Frames  Skips  Compressed  Uncompressed  Ratio  Check  Filename
     1      0    26.0 KiB       106 KiB  4.083  XXH64  notes.txt.zst
Error: could not read checksum
Error while parsing "cut.zst"
     0      0    19.5 KiB       106 KiB  5.445  XXH64  cut.zst
-----------------------------------------------------------------
     1      0    45.6 KiB       213 KiB  4.666  XXH64  2 files

With this change, when the frame header, a block header or the checksum is short because the end of the file was reached, FIO_analyzeFrames() returns info_truncated_input, as it already does for frames without a checksum:

Error: could not read checksum
File "cut.zst" is truncated
-----------------------------------------------------------------
     1      0    26.0 KiB       106 KiB  4.083  XXH64  1 files

A short read that is not at the end of the file, and a frame that is complete but invalid (for example a reserved block type), are still reported as parse errors. The exit code is 1 in both cases, as before.

Recording (dev, then this branch, then edge cases):

zstd-list-truncated.mp4

Test

New tests/cli-tests/basic/list-truncated.sh: for a frame with and without a checksum, cut at 6 bytes (frame header), 9 bytes (first block header), 100 bytes (block data) and one byte short of the end, zstd -l must fail and say is truncated. It fails on dev (frame truncated to 6 bytes not reported as truncated) and passes on this branch. basic/list-short-skippable.sh, basic/args.sh, basic/help.sh and basic/version.sh still pass.

Edge cases and unchanged behaviour checked (all in the running CLI, shown in the recording):

  • cut inside the frame header, and inside the first block header: reported as truncated
  • frame without a checksum cut inside block data: still reported as truncated
  • complete file: listed as before
  • complete frame with a reserved block type: still "Error while parsing" with its row
  • plain text file: still "not compressed by zstd"

Checklist

  • I searched open pull requests and issues: this problem is not already being addressed.
  • Bug fix: it comes with a reproducer or a test that fails without the fix.
  • Performance change: numbers from repeated runs are included, with CPU, compiler, flags and data.
    A gain in one configuration is not a general gain: see the Performance section of CONTRIBUTING.md.
  • I stated below whether AI or other automated tools were used.

Tools used

An AI coding agent (Claude Code) found the problem while testing zstd -l on cut files, wrote the change and the test, ran the tests listed above and recorded the video, under my account and at my request.

🤖 Generated with Claude Code

zstd -l only recognised truncation in a frame without a checksum, when
the cut fell inside block data. A file cut inside the frame header, a
block header, or before the checksum (the CLI writes one by default)
was reported as "Error while parsing" plus a table row with 0 frames and
a ratio computed from the full declared content size.

When the frame header, a block header or the checksum is short because
the end of the file was reached, report the file as truncated, as is
already done for frames without a checksum.
@meta-cla meta-cla Bot added the CLA Signed label Dec 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant