Bugzilla – Bug 669
Floating point crash repeating less than a sample of audio
Last modified: 2018-08-20 11:45:31 UTC
If the "Repeat" affect is applied to a "selection" of less than 1 sample duration, Audacity will crash (see steps to reproduce). "Repeat" cannot be sensibly applied to "no samples" and currently it causes a divide by zero error in src/effects/Repeat.cpp at around line 69.
Created attachment 420 [details] Display error if selection less than 1 sample duration If the selection is less than 1 sample duration, an error is returned: "Selection too short to repeat."
Not tested the patch. I've tested with 0 samples selected at the edge of a clip but "samples" selected in the following white space. That does not crash so I think P4 is reasonable.
(In reply to comment #2) After further testing, the patch that I posted is not completely foolproof and can still trigger an assert if there are multiple tracks with different sample rates. I don't see how to remove a posted patch, so please ignore it and I'll post a new patch when I can fix the remaining issue.
Created attachment 421 [details] Prevents divide by zero error Divide by zero will occur when attempting to repeat any track that has a selection length of zero sample periods. The previous patch could fail in projects containing tracks with different sample rates. This version prevents attempting to repeat the selection if any track has a selection of zero sample periods.
(In reply to comment #4) Tested, did not get any crashes. Re: the maximum sample count - is it 2^31 (2,147,483,648) ? If so I don't see why generating (2,147,483,648 / 4) = 536,870,912 samples then only allows you 2 repeats for a total of 10h 08 mins 42 secs. Yet it allows you to repeat 4 samples 536,870,912 times (not that I think that would complete any time soon...)
(In reply to comment #5) Comment 5 is not part of this bug, and the patch does not change the current behaviour with regard to maximum track length, but a brief explanation of what is going on: "Repeat" allows a maximum sample count of (2^31) - 1 = 2,147,483,647 2 repeats gives a result of 3 times the original length. 536,870,912 x 3 = 1,610,612,736 2,147,483,647 - 1,610,612,736 = 536,870,911 No room for a 3rd repeat. If I select 4 samples by double clicking on a track of length 4 samples (sample rate 44100), I'm allowed to repeat 536,870,910 times. This gives a total length of: 4 x (536,870,910 + 1) = 2,147,483,644 2,147,483,647 - 2,147,483,644 = 3 No room for a 536,870,911th repeat. As the number of samples is an integer, calculated from the length and sample rate, the sample count may be rounded up or down depending on how the selection is made. This is academic really as Audacity projects can be considerably bigger than this, but I left the check in place because bug 416 is still open. I doubt there are any common scenarios where this is a problem, other than trying to break something. I added a comment to this effect.
(In reply to comment #6) > Comment 5 is not part of this bug, and the patch does not change the current > behaviour with regard to maximum track length Yes sorry I only realised that afterwards, I saw the additions but not the subtractions in the diff. Marked patch_ready.
(In reply to comment #7) Committed a much simpler version of this fix, eliminating the bool, and just putting up the message box, then returning false, when selectionLen is found to be zero.
Thanks, Vaughan and Steve.