Bugzilla – Bug 605
snd-const function with a negative duration causes Audacity to crash
Last modified: 2018-08-20 11:51:40 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.
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.
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.
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.
Marked as patch_closed and RESOLVED-FIXED. Debug output on Windows shows the negative value used.