Undo Pasting Over Whole Sample Permanently Deletes Waveform

First load a song that contains samples, then copy some sample data into the clipboard. Pasting over part of a sample then undoing that works as normal. Pasting over the whole sample then undoing permanently deletes the whole waveform. Doing this to samples created or loaded in after the initial song load works fine.

Interestingly, this bug only applies to versions 2.8 and later. Previous versions will undo the pasting and restore the original waveform as normal.