Fix off-by-one boundary in lpEncodeBacklen() for 3 values#3601
Merged
Conversation
The function lpEncodeBacklen() uses `<= 127` for the 1-byte case but `< 16383`, `< 2097151`, and `< 268435455` for the subsequent cases. This means the exact values 16383, 2097151, and 268435455 (i.e. 2^14-1, 2^21-1, 2^28-1) unnecessarily use one extra byte than needed. For example, 16383 (0x3FFF) can be encoded in 2 bytes but is currently encoded in 3 bytes due to the boundary check being off by one. Signed-off-by: fanpei91 <fanpei91@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #3601 +/- ##
============================================
- Coverage 76.64% 76.62% -0.03%
============================================
Files 160 160
Lines 80475 80475
============================================
- Hits 61684 61660 -24
- Misses 18791 18815 +24
🚀 New features to boost your workflow:
|
lucasyonge
pushed a commit
that referenced
this pull request
May 11, 2026
The function lpEncodeBacklen() uses `<= 127` for the 1-byte case but `< 16383`, `< 2097151`, and `< 268435455` for the subsequent cases. This means the exact values 16383, 2097151, and 268435455 (i.e. 2^14-1, 2^21-1, 2^28-1) unnecessarily use one extra byte than needed: - `l < 16383` → `16383` (2^14-1) uses 3 bytes instead of 2 - `l < 2097151` → `2097151` (2^21-1) uses 4 bytes instead of 3 - `l < 268435455` → `268435455` (2^28-1) uses 5 bytes instead of 4 The decoding side (`lpDecodeBacklen`) is unaffected since it parses continuation bits continuously without discrete range checks. This is a correctness issue and has no impact on data integrity since encoding and decoding use the same function boundaries, but it wastes up to 1 byte per affected entry. Signed-off-by: fanpei91 <fanpei91@gmail.com>
lucasyonge
pushed a commit
that referenced
this pull request
May 12, 2026
The function lpEncodeBacklen() uses `<= 127` for the 1-byte case but `< 16383`, `< 2097151`, and `< 268435455` for the subsequent cases. This means the exact values 16383, 2097151, and 268435455 (i.e. 2^14-1, 2^21-1, 2^28-1) unnecessarily use one extra byte than needed: - `l < 16383` → `16383` (2^14-1) uses 3 bytes instead of 2 - `l < 2097151` → `2097151` (2^21-1) uses 4 bytes instead of 3 - `l < 268435455` → `268435455` (2^28-1) uses 5 bytes instead of 4 The decoding side (`lpDecodeBacklen`) is unaffected since it parses continuation bits continuously without discrete range checks. This is a correctness issue and has no impact on data integrity since encoding and decoding use the same function boundaries, but it wastes up to 1 byte per affected entry. Signed-off-by: fanpei91 <fanpei91@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The function lpEncodeBacklen() uses
<= 127for the 1-byte case but< 16383,< 2097151, and< 268435455for the subsequent cases. This means the exact values 16383, 2097151, and 268435455 (i.e. 2^14-1, 2^21-1, 2^28-1) unnecessarily use one extra byte than needed:l < 16383→16383(2^14-1) uses 3 bytes instead of 2l < 2097151→2097151(2^21-1) uses 4 bytes instead of 3l < 268435455→268435455(2^28-1) uses 5 bytes instead of 4The decoding side (
lpDecodeBacklen) is unaffected since it parses continuation bits continuously without discrete range checks.This is a correctness issue and has no impact on data integrity since encoding and decoding use the same function boundaries, but it wastes up to 1 byte per affected entry.