korginc / volcasample

volca sample SDK - a sample and sequence encoding library for volca sample.
http://korginc.github.io/volcasample/index.html
BSD 3-Clause "New" or "Revised" License
351 stars 37 forks source link

SyroComp_CompBlock: Prevent stack buffer overflow #19

Open benwiley4000 opened 2 years ago

benwiley4000 commented 2 years ago

Closes #18.

I found a stack buffer overflow in SyroComp_CompBlock that didn't seem to result in any bugs when I compiled code with GCC.. however I consistently ran into problems when compiling to WebAssembly with Emscripten.

In this code:

https://github.com/korginc/volcasample/blob/b0ed615f18c230a18b378d9ddc6a936971597e4e/syro/korg_syro_comp.c#L394-L403

We can see that once j has been incremented to 4, the index 4 of BitBase (which doesn't exist) will be checked for the remainder of the loop. If the out of bounds memory happens to match i by accident, then we will get a false positive and write incorrect data.

Adding the index guard in this pull request solves the problem and makes my tests pass (for both GCC and Emscripten).