Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(enc): properly handle large buffers with
libvorbis
patch
Issue #17 reported a crash I could reproduce when trying to encode very large sample buffers. After some investigation, I narrowed down the cause to an `alloca` whose allocation size was dependent on the input buffer size, which incurs in undefined behavior if the stack is too small. (This is why modern C coding guidelines discourage the usage of `alloca`.) I considered two approaches to fix this: - The `vorbis_rs` crate could introduce a dependency on the `stacker` crate to allocate the stack on the heap if it turns out to be too small to hold this `alloca` buffer. However, that couples the `vorbis_rs` crate with an internal implementation detail of `libvorbis`, requires complex stack pointer manipulation techniques not available on all platforms, and introduces quite a few transitive dependencies. - I could modify `libvorbis` to allocate this buffer on the heap if it is too big. This approach is very simple and, while it may come at a very minor performance cost for (re)allocating an array at most each time a block is submitted, it's otherwise similar to growing the stack on the heap. I liked the second option more, so I went for it. Fixes #17.
- Loading branch information