-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
stack overflow due to an infinite recursion (on 32-bit) #247
Comments
Good catch, @gockelhahn ! Action plan is: (1) Write "safer" And here's an example (not tested): static int LZ4IO_internal_fseek(FILE *fp, unsigned offset, int where) {
/* Here, we want to use LONG_MAX. But since offset is `unsigned`, we should use INT_MAX.
Because INT_MAX <= UINT_MAX <= LONG_MAX.
Also note that LZ4 doesn't require `signed long long`. It only uses `unsigned long long`.
*/
const unsigned stepMax = INT_MAX;
int errorNb = 0;
/* Only allows SEEK_CUR */
if(where != SEEK_CUR) {
errorNb = -1;
} else {
while (offset > 0) {
unsigned s = offset;
if (s > stepMax) {
s = stepMax;
}
errorNb = fseek(fp, (long) s, SEEK_CUR);
if (errorNb != 0) {
break;
}
offset -= s;
}
}
return errorNb;
}
static unsigned long long selectDecoder(dRess_t ress, FILE* finput, FILE* foutput)
{
...
switch(magicNumber)
{
...
case LZ4IO_SKIPPABLE0:
...
size = LZ4IO_readLE32(MNstore); /* Little Endian format */
- errorNb = fseek(finput, size, SEEK_CUR);
+ errorNb = LZ4IO_internal_fseek(finput, size, SEEK_CUR);
...
}
} @Cyan4973 , do you find any other TODOs and/or better idea for this issue? |
Excellent catch @gockelhahn , Thanks ! and yes, I fully agree with your detailed and complete action plan @t-mat . |
Latest update of It uses both a safer version of Btw, I'm really impressed you found the issue through afl. |
@Cyan4973 - i only used the recent stock afl ... ... thanks for fixing it! |
while fuzzing with afl, a crash has been found after compiling lz4 as 32-bit binary:
it happens when we try to decompress a crafted lz4 file:
hexdump of the first crash file:
hexdump of the second crash file:
hexdump of another file where the process is stuck in 100% CPU load,
probably this has also something to do with the magic number:
The text was updated successfully, but these errors were encountered: