PyTorch sparse in-place add can write past tensor views
A double-counted storage offset on CPU shifts sparse updates and can corrupt memory outside the view.
An in-place sparse addition in PyTorch can write past the end of a dense tensor view when that view does not start at the beginning of its underlying storage. Mengxi-Xu reported the bug against a recent development build, showing that the CPU path for adding a sparse tensor into a dense one applies the view's storage offset twice: the data pointer already includes it, and the write index adds it again.
Every update then lands one element too far. On a contiguous slice such as the middle of a longer tensor, the last value is written outside the view. When the sparse and dense dtypes match, PyTorch reuses the caller's tensor instead of a temporary copy, so the bad writes go straight into user storage and can change elements the slice was never supposed to touch.
In the report's four-element example, adding into the middle two positions leaves the first element unchanged, shifts both sparse values one slot right, and overwrites the element past the view. The expected result would update only those two middle elements. The suggested correction is to stop adding the offset a second time, and optionally to copy a non-zero-offset view into a contiguous buffer before writing back.