std.sort.pdq: fix out-of-bounds access in partialInsertionSort - #25253
Merged
Merged
Conversation
When sorting a sub-range that doesn't start at index 0, the partialInsertionSort function could access indices below the range start. The loop condition `while (j >= 1)` didn't respect the arbitrary range boundaries [a, b). This changes the condition to `while (j > a)` to ensure indices never go below the range start, fixing the issue where pdqContext would access out-of-bounds indices. Fixes ziglang#25250
neoto
reviewed
Sep 17, 2025
andrewrk
approved these changes
Sep 18, 2025
andrewrk
left a comment
Member
There was a problem hiding this comment.
Thank you. This will be a nice example to see if it can be caught by integrated fuzzer when that sub-project is further along.
alexrp
pushed a commit
that referenced
this pull request
Sep 18, 2025
* std.sort.pdq: fix out-of-bounds access in partialInsertionSort When sorting a sub-range that doesn't start at index 0, the partialInsertionSort function could access indices below the range start. The loop condition `while (j >= 1)` didn't respect the arbitrary range boundaries [a, b). This changes the condition to `while (j > a)` to ensure indices never go below the range start, fixing the issue where pdqContext would access out-of-bounds indices. Fixes #25250
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.
When sorting a sub-range that doesn't start at index 0, the
partialInsertionSortfunction could access indices below the range start.The loop condition
while (j >= 1)didn't respect the arbitrary range boundaries[a, b).This changes the condition to
while (j > a)to ensure indices never go below the range start, fixing the issue wherepdqContextwould access out-of-bounds indices.Fixes #25250