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.
The
study
method callsalloca
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.)