breakfastquay / rubberband

Official mirror of Rubber Band Library, an audio time-stretching and pitch-shifting library.
http://breakfastquay.com/rubberband/
GNU General Public License v2.0
561 stars 89 forks source link

Avoid stack overflow in R2Stretcher::study. #102

Closed psobot closed 1 month ago

psobot commented 2 months ago

The study method calls alloca in a loop, which causes a large amount of data to be allocated on the stack - proportional to the provided input. (alloca does not follow C++'s RAII rules; the allocated memory stays on the stack until the function exits, rather than the enclosing scope.) With a large enough input, this can cause a stack overflow.

This PR avoids the problem by only calling alloca at most once and re-using the buffer if necessary.

(Discovered by @f0k in https://github.com/spotify/pedalboard/issues/340.)

cannam commented 2 months ago

Oof, that's nasty. Thanks for the report! I may look at doing this without alloca (which was always a bit gross).

cannam commented 1 month ago

Fixed in 832f577. Thanks again!