Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyroComp_CompBlock: Prevent stack buffer overflow #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

benwiley4000
Copy link

@benwiley4000 benwiley4000 commented Oct 19, 2021

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:

/*----- wrtie bit-base ------*/
j = 0;
for (i=0; i<16; i++) {
if (pBitBase[j]==i) {
BitHead[i] = j++;
SyroComp_WriteBit(&wp, (uint32_t)(i-1), 4);
} else {
BitHead[i] = -1;
}
}

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compiling SYRO to WebAssembly (DataType_Sample_Compress corruption)
1 participant