Commit a3926e2
committed
Fix: OOB read in
The tail used masked loads with different masks for `a` and `b`, then an
unmasked `_mm512_cmpneq_epi8_mask`. When one string was shorter, its
masked-off lanes were zero, so the longer string's bytes in those lanes
compared as "not equal" against zero, producing spurious mismatch bits
beyond `min(a_length, b_length)`. The follow-up `a[first_diff]` /
`b[first_diff]` then read past the shorter buffer and could return a
wrong ordering whenever the random byte at the OOB index outranked the
real one — manifesting in `sz_sequence_argsort_with_insertion` as the
empty string being placed after non-empty strings starting with `\0`,
which made `test_sorting_algorithms` abort on the `"ab\0"` alphabet.
Restrict the compare to `a_mask & b_mask` (the bytes valid in both)
using the masked `_mm512_mask_cmpneq_epi8_mask`, mirroring how the head
section and `sz_equal_skylake` already handle masked tails.sz_order_skylake tail for length-mismatched strings1 parent 267c757 commit a3926e2
1 file changed
Lines changed: 6 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
374 | 374 | | |
375 | 375 | | |
376 | 376 | | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
381 | 383 | | |
382 | 384 | | |
383 | 385 | | |
| |||
0 commit comments