Skip to content

cli: clamp --adapt=min= and max= to the supported levels - #4982

Open
Mattbusel wants to merge 1 commit into
meta:devfrom
Mattbusel:cli-clamp-adapt-bounds
Open

Mattbusel wants to merge 1 commit into
meta:devfrom
Mattbusel:cli-clamp-adapt-bounds

Conversation

@Mattbusel

Copy link
Copy Markdown

What and why

Fixes #4980.

parseAdaptParameters() only checked min <= max. A minimum below ZSTD_minCLevel() then reached FIO_setAdaptMin(), whose assert aborts a default make build:

$ ./programs/zstd -f --adapt=min=-200000 f -o f.zst
Assertion failed: (minCLevel >= ZSTD_minCLevel()), function FIO_setAdaptMin ...
exit code 134

With -DNDEBUG the value went through unchecked.

This PR clamps both bounds to [MINCLEVEL, MAXCLEVEL] after the existing coherence check, the same way -# and --fast=# already clamp levels. I chose clamping over rejecting so that values the CLI accepts today, such as --adapt=max=99, keep working. To make that possible, the MINCLEVEL / MAXCLEVEL defines moved up above parseAdaptParameters(). They are unchanged, including the ZSTD_NOCOMPRESS fallback.

This does not overlap with #4873, which handles values above INT_MAX.

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: not applicable.
  • I stated below whether AI or other automated tools were used.

Test

New cases in tests/cli-tests/compression/adapt.sh: --adapt=min=-200000, min=-200000,max=-200000, min=1,max=200000 and min=200000,max=200000. All four must compress and round-trip through zstd -t.

Built on dev (cfd06da) with the default Makefile flags, gcc on Debian x86_64:

  • Without the change, adapt.sh fails ("Exit code mismatch! Expected 0 but got 1", from the SIGABRT).
  • With it, run.py passes compression/adapt.sh, compression/levels.sh and compression/basic.sh.
  • --adapt=min=10,max=9 still exits 1 with "Incorrect parameter".
  • make -C programs zstd-decompress (ZSTD_NOCOMPRESS) still builds.

Tools used

Claude (Anthropic) helped write the change and the test. I reproduced the abort and ran the tests above myself. The commit has an Assisted-by trailer.

@meta-cla

meta-cla Bot commented Nov 18, 2026

Copy link
Copy Markdown

Hi @Mattbusel!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

parseAdaptParameters() only checked min <= max. A minimum below
ZSTD_minCLevel() reached FIO_setAdaptMin(), whose assert aborts the
default build with SIGABRT; with NDEBUG the value went through
unchecked. Clamp both bounds to [MINCLEVEL, MAXCLEVEL], the way -# and
--fast=# already clamp levels, so previously accepted values such as
--adapt=max=99 keep working.

Fixes meta#4980

Assisted-by: Claude:claude-opus-5-5
@Mattbusel
Mattbusel force-pushed the cli-clamp-adapt-bounds branch from c91fccd to f839634 Compare November 18, 2026 02:06
@meta-cla meta-cla Bot added the CLA Signed label Nov 18, 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.

CLI: --adapt=min= below ZSTD_minCLevel() aborts the default build (assertion in FIO_setAdaptMin)

1 participant