Skip to content

chunkers: range-check size exponents, reject negative fixed header_size - #10628

Merged
ThomasWaldmann merged 1 commit into
borgbackup:masterfrom
ThomasWaldmann:chunker-exp-header-checks
Nov 14, 2026
Merged

ThomasWaldmann merged 1 commit into
borgbackup:masterfrom
ThomasWaldmann:chunker-exp-header-checks

Conversation

@ThomasWaldmann

Copy link
Copy Markdown
Member

Follow-up to #10603 (found while reviewing its 1.4-maint backport #10619).

Changes

  • The chunkers compute the min/max chunk sizes as 1 << chunk_min_exp / 1 << chunk_max_exp with C int operands, so their parameter checks only work on well-defined shift results. A new _check_size_exps() (in chunkers/base.pxd) raises ValueError unless both exponents are in 0..30. It runs before any shift: in ChunkerBase._setup_common (FastCDC, PHTE/AES chunkers) and in the buzhash / buzhash64 constructors, which do their window-fit check before calling _setup_common.
  • ChunkerParams rejects a negative header_size for the fixed chunker, so only valid chunker params get stored in archive metadata.

ChunkerParams already limits the buzhash/fastcdc exponents to 6..23, so this only affects direct constructor calls; cut points are unchanged.

Testing

  • New cases in test_chunkers_reject_invalid_params (exponent 40 for fastcdc, buzhash, buzhash64; negative exponent for fastcdc) and test_invalid_chunkerparams (fixed,4096,-1). All 5 fail without the fix and pass with it.
  • testsuite/chunkers/, parseformat_test.py and the archiver -k "chunker or rechunk or recreate or benchmark" tests pass; python -O still gets the ValueError.

🤖 Generated with Claude Code

The chunkers compute min/max chunk sizes as 1 << chunk_min_exp and
1 << chunk_max_exp with C int operands, so their parameter checks only
work on well-defined shift results. They now raise ValueError unless both
exponents are in 0..30, before any shift (ChunkerBase._setup_common and
the buzhash / buzhash64 constructors, which check the window fit first).

ChunkerParams now also rejects a negative header_size for the fixed
chunker, so only valid chunker params get stored in archive metadata.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.45%. Comparing base (58231e6) to head (0b58a28).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #10628   +/-   ##
=======================================
  Coverage   89.45%   89.45%           
=======================================
  Files         105      105           
  Lines       20339    20341    +2     
  Branches     3198     3199    +1     
=======================================
+ Hits        18194    18196    +2     
- Misses       1489     1491    +2     
+ Partials      656      654    -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@ThomasWaldmann

Copy link
Copy Markdown
Member Author

@m3nu ^

@m3nu

m3nu commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Verified locally and works as intended. All 5 tests fail pre-fix, but raise as intended after.

@ThomasWaldmann
ThomasWaldmann merged commit 119addc into borgbackup:master Nov 14, 2026
27 checks passed
@ThomasWaldmann
ThomasWaldmann deleted the chunker-exp-header-checks branch November 14, 2026 15:55
ThomasWaldmann added a commit that referenced this pull request Nov 14, 2026
Backport of the master change from #10628.

Chunker.__cinit__ computes the min/max chunk sizes as 1 << chunk_min_exp
and 1 << chunk_max_exp with C int operands, so its parameter checks only
work on well-defined shift results. It now raises ValueError unless both
exponents are in 0..30, before any shift.

ChunkerParams now also rejects a negative header_size for the fixed
chunker, so only valid chunker params get stored in archive metadata.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants