# std.sort.pdq: fix out-of-bounds access in partialInsertionSort \(\#25253\) · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/91eab35e08f72220fd2461bdf6da2f74aaff5c64)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 91eab35e08f72220fd2461bdf6da2f74aaff5c64

Requested commit: 91eab35e08f72220fd2461bdf6da2f74aaff5c64

Commit: 91eab35e08f72220fd2461bdf6da2f74aaff5c64

Tree: 43f85dd5411abcbc4e9f478ec81bb966b6f282f4

Author: Frank Denis

Committer: Alex Rønne Petersen

## Message

```
std.sort.pdq: fix out-of-bounds access in partialInsertionSort (#25253)

* 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

```

## Parents

- [ac562577381f6e94196337e0ccd8895bd1bcddb2](https://git.cafe/gitcafe/zig/commit/ac562577381f6e94196337e0ccd8895bd1bcddb2?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/91eab35e08f72220fd2461bdf6da2f74aaff5c64?format=markdown)
