qmdb/sync/gaps: clamp checked_add to range.end instead of unwrap-panic#3706
Open
SAY-5 wants to merge 1 commit into
Open
qmdb/sync/gaps: clamp checked_add to range.end instead of unwrap-panic#3706SAY-5 wants to merge 1 commit into
SAY-5 wants to merge 1 commit into
Conversation
danlaine
reviewed
May 4, 2026
Comment on lines
+40
to
+46
| // `Location::checked_add` returns `None` on overflow *or* when the result | ||
| // exceeds `Family::MAX_LEAVES`. The previous unconditional `.unwrap()` | ||
| // panicked on fuzzer-generated inputs that placed `start_loc` near the | ||
| // ceiling. Clamp such ranges to `range.end` instead — semantically the | ||
| // batch is already at the boundary, so the merge logic terminates the | ||
| // loop on the next iteration as expected (#2068). | ||
| let range_end = range.end; |
Collaborator
There was a problem hiding this comment.
I think this is cleaner with just the .unwrap_or changes.
Suggested change
| // `Location::checked_add` returns `None` on overflow *or* when the result | |
| // exceeds `Family::MAX_LEAVES`. The previous unconditional `.unwrap()` | |
| // panicked on fuzzer-generated inputs that placed `start_loc` near the | |
| // ceiling. Clamp such ranges to `range.end` instead — semantically the | |
| // batch is already at the boundary, so the merge logic terminates the | |
| // loop on the next iteration as expected (#2068). | |
| let range_end = range.end; |
Author
|
Agreed, I'll trim the diff to just the |
Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>
a1878a5 to
9db797e
Compare
Author
|
Pushed 9db797e, trimmed the diff to just the two .unwrap_or(range.end) replacements. |
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.
Fixes #2068.
Location::checked_addreturnsNoneon overflow OR when the result exceedsFamily::MAX_LEAVES. The two callsites ingaps::find_nextunconditionally.unwrap()'d the result, so fuzzer inputs withstart_locnear the family ceiling panicked the sync engine.Clamp to
range.endonNoneso the merge loop terminates on the next iteration as expected, instead of crashing.