slices: Incorrect implementation of slices.Insert and slices.Replace #60138
Labels
FrozenDueToAge
NeedsFix
The path to resolution is known, but the work has not been done.
release-blocker
Milestone
What did you do?
Crafted an example such that the memory referenced by the result overlaps with the insert-from slice, playground
What did you expect to see?
What did you see instead?
Note: This is because the implementation of
slices.Insert
slides the upper range of the first operand forward before copying the content of the third operand into the freed space. This risks overwrite the content in that operand. I believeslices.Replace
suffers the same issue, too.A conservative solution is to create a temporary buffer to copy the content of the second slice into before sliding the first one, while a more aggressive one would be to do pointer arithmetic to check the aliasness.
The text was updated successfully, but these errors were encountered: