You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
kernels: Bin32 and Sqrt32 read past a short operand's length when it has spare capacity #130
Bin32 and Sqrt32 in internal/kernels/bin32.go (lines 23 and 62 at #129's head da8b2bf; the same code is on main) cut their inputs with a[:n], where n = len(dst). Go bounds-checks a reslice against the slice's capacity, not its length, so an input shorter than dst but with spare capacity is accepted, and the kernel reads elements past its length.
The review of #129 reproduced it: a with len 3 and cap 4, dst of length 4. The call succeeded and wrote dst = [1 2 3 99], where 99 is the element beyond len(a).
The comments and the PR text say a shorter operand is refused, but that is only true when cap == len. Every test fixture uses make, where cap == len, so no test can see it.
Fix: compare lengths explicitly (if len(a) < n || len(b) < n { ... }) before reslicing, in both functions. Add a test whose operand has spare capacity, with a fixture built by reslicing a longer backing array to a shorter length. A mutant that removes the explicit check must turn that test red.
Prior art: priorart "Bin32 Sqrt32 capacity reslice read past length" at 2026-11-22 13:57 CET reported prior art; checked: 60 keyword hits; the relevant ones are #129 (the PR whose review found this), #98 (the floats migration), #59/#61 (the kernels' origin); none reports this over-read
Activity