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

Audacity Bugzilla



Bug 605 - snd-const function with a negative duration causes Audacity to crash
snd-const function with a negative duration causes Audacity to crash
Status: RESOLVED FIXED
Product: Audacity
Classification: Unclassified
Component: Nyquist
unspecified
PC All
: P4 Repeatable
Assigned To: Default Assignee for New Bugs
: nyquist, patch_closed
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-12-09 14:22 UTC by Steve Daulton
Modified: 2018-08-20 11:51 UTC (History)
7 users (show)

See Also:
Steps To Reproduce:
Apply the following code to a selection using the Nyquist Prompt: (snd-const -1 0 *sound-srate* -1)
Release Note:
First Git SHA:
Group: ---
Workaround:
Closed: 2018-08-20 00:00:00
petersampsonaudacity: Test‑OK‑Win+
petersampsonaudacity: Test‑OK‑Mac+
stevethefiddle: Test‑OK‑Lin+


Attachments
patch to const.alg and const.c (996 bytes, patch)
2012-12-09 14:22 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 2012-12-09 14:22:44 UTC
Created attachment 337 [details]
patch to const.alg and const.c

snd-const is a low level function in Nyquist (implemented in computer generated
C)

Entering a negative value for the "duration" parameter causes Nyquist to crash
and Audacity follows it.

A possible solution would be to force "d" to be positive.
I've attached a patch that seems to do the trick but as it is a change to
Nyquist then I think this is one for Rodger Dannenberg.
Comment 1 Roger Dannenberg 2012-12-09 14:50:49 UTC
Very interesting! This is also a problem for other unit generators, e.g. osc.c, so I think the best fix will be to automatically generate code to prevent terminate_cnt from becoming negative. I will do this before we release Nyquist for my class in January. (We're working on some other aspects of Nyquist too.) There will still be some overflow problems, e.g. if you make a sound so long that the termination sample count wraps around into the "magic" sample count called UNKNOWN, I think bad things will happen. We could check every integer sample count operation for overflow and be much more defensive (and these days when 2^32 samples is not at all far-fetched, maybe we should), but I'm not putting that as a high priority -- I guess I'm willing to patch every hole that someone can demonstrate actually causes a crash and otherwise, I'll defer this unless I hear real concerns about this set of defects. If I test terminate_cnt AFTER multiplying sample rate by duration, I'll catch some overflow problems as well as negative duration bugs. I think that will help, and the right result is to throw a Nyquist error rather than set the duration to zero; otherwise, very long sounds which are in principle well-defined would silently be truncated to zero duration, which would be surprising.
Comment 2 Steve Daulton 2016-01-20 17:23:19 UTC
This is fixed in the current version of Nyquist.
As can be seen by running the test code from the "steps to reproduce" with the Debug button:
(snd-const -1 0 *sound-srate* -1)
The invalid "duration" (-1) is now handled and Nyquist throws an error:
"error: duration is less than 0 samples
Function: #<Subr-SND-CONST: #b1be128>
Arguments:
  -1
  0
  44100
  -1"

Marked as "Devel-Fix Made".
I think this bug may now be closed.
Comment 3 Peter Sampson 2016-02-20 07:08:21 UTC
Testing on Mac El Capitan on 01a95c5-2.1.3-alpha-13-feb-16
and
Testing on W10 on aud audacity-win-rf933621-2.1.3-alpha-19-feb-16

Running this command (in the steps to reproduce) does not cause a crash on either platform.
Comment 4 Gale Andrews 2017-01-21 20:09:35 UTC
Marked as patch_closed and RESOLVED-FIXED. Debug output on Windows shows the negative value used.