Audacity Bug Summary
••• Introduction •••
••• Keywords •••
    Audacity 3.0.3 development began 19th April 2021

Audacity Bugzilla



Bug 669 - Floating point crash repeating less than a sample of audio
Floating point crash repeating less than a sample of audio
Status: RESOLVED FIXED
Product: Audacity
Classification: Unclassified
Component: Built-in FX
unspecified
PC All
: P4 Repeatable
Assigned To: Default Assignee for New Bugs
http://forum.audacityteam.org/viewtop...
: Cherry, patch_ready
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-10-13 09:31 UTC by Steve Daulton
Modified: 2018-08-20 11:45 UTC (History)
6 users (show)

See Also:
Steps To Reproduce:
1 Generate Tone 2 Zoom in to maximum 3 drag-select a small distance in the waveform without drawing a selection there (that is, the selection will only be in the Timeline) 4 Effect > Repeat.
Release Note:
First Git SHA:
Group: ---
Workaround:
Closed: 2018-08-20 00:00:00


Attachments
Display error if selection less than 1 sample duration (1.16 KB, patch)
2013-10-13 10:02 UTC, Steve Daulton
Details | Diff
Prevents divide by zero error (1.61 KB, patch)
2013-10-16 23:00 UTC, Steve Daulton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Daulton 2013-10-13 09:31:18 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.
Comment 1 Steve Daulton 2013-10-13 10:02:48 UTC
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."
Comment 2 Gale Andrews 2013-10-13 13:19:31 UTC
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.
Comment 3 Steve Daulton 2013-10-13 14:58:39 UTC
(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.
Comment 4 Steve Daulton 2013-10-16 23:00:56 UTC
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.
Comment 5 Gale Andrews 2013-10-18 04:12:36 UTC
(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...)
Comment 6 Steve Daulton 2013-10-18 09:17:20 UTC
(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.
Comment 7 Gale Andrews 2013-10-18 11:51:43 UTC
(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.
Comment 8 Vaughan Johnson 2013-10-18 16:17:49 UTC
(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.
Comment 9 Gale Andrews 2013-10-25 00:26:17 UTC
Thanks, Vaughan and Steve.