Skip to content

cli: fix --memlimit-decompress= argument parsing - #4916

Open
ZainnQureshii wants to merge 1 commit into
meta:devfrom
ZainnQureshii:fix/memlimit-decompress-alias
Open

ZainnQureshii wants to merge 1 commit into
meta:devfrom
ZainnQureshii:fix/memlimit-decompress-alias

Conversation

@ZainnQureshii

Copy link
Copy Markdown

What and why

At programs/zstdcli.c:1105, --memlimit matched before --memlimit-decompress. For zstd -dc --memlimit-decompress=8M input.zst, that left -decompress=8M for NEXT_FIELD (programs/zstdcli.c:827), which read input.zst as the numeric value and exited 1. Moving --memlimit-decompress ahead of --memlimit leaves =8M, reads 8M, and decompresses successfully with exit 0.

tests/cli-tests/basic/memlimit_alias.sh:6 checks --memlimit, --memory and --memlimit-decompress, using both =8M and separate 8M arguments, comparing decompressed output, and checking the window-size diagnostic with =1K.

Commands run from the repository root:

Command Result
make -j4 zstd-release Exit 0 with the original and fixed parser.
make -C tests datagen Exit 0.
python3 tests/cli-tests/run.py basic/memlimit_alias.sh Original parser: exit 1, 0 passed, 1 failed, numeric-value error. Fixed parser: exit 0, 1 passed, 0 failed.
python3 tests/cli-tests/run.py tests/cli-tests/basic/*.sh Exit 0, 6 passed, 0 failed, including after restoring the fix.
make check Exit 2 with both parsers at tests/playTests.sh:521: writing to /dev/zero fails with Operation not permitted. No test totals reported.
make staticAnalyze Exit 2: scan-build is unavailable; analysis did not run.
xcrun clang-format -lines=1105:1107 programs/zstdcli.c Exit 0; inspected output, retained adjacent project style per CONTRIBUTING.md.
sh -n tests/cli-tests/basic/memlimit_alias.sh Exit 0.
git diff --check Exit 0.

Checklist

  • I searched open pull requests and issues: this problem is not already being addressed.
    Duplicate check: gh pr list -R meta/zstd --state open --search "zstdcli.c" --json number,title,url --limit 100, returned five PRs; their diffs do not change the alias ordering.
  • 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.
    Not applicable: CLI argument parsing fix.
  • I stated below whether AI or other automated tools were used.

Tools used

Claude Code (with Codex) found the problem, wrote the patch and regression test, independently attacked the fix, ran verification and prepared this draft. GitHub Copilot then reviewed the diff and found no issues.

Prepared with AI assistance (Claude Code) and reviewed with GitHub Copilot.

🤖 Generated with Claude Code

longCommandWArg() matches by prefix, and the --memlimit branch came
before --memlimit-decompress, so --memlimit-decompress=8M matched
--memlimit and left "-decompress=8M" for NEXT_UINT32, which then read
the next argument as the value. Check the longer alias first, and add a
CLI test for all three spellings in both argument forms.
@meta-cla meta-cla Bot added the CLA Signed label Nov 10, 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