Commit Graph

2203 Commits

Author SHA1 Message Date
Randy a6b384358f Merge branch 'fuzzer_updates' of https://github.com/randy408/stb into fuzzer_updates 2020-06-01 06:03:50 +02:00
Randy a7fed59fe4 add fuzz target to Makefile 2020-06-01 06:01:40 +02:00
Colton G. Rushton 9e292f0731
Fix minor typo in comment on line 6532 2020-05-30 17:41:25 -03:00
Recep Aslantas ec898982b0 stbi: use __thread if GCC can't use _Thread_local 2020-05-26 00:22:12 +03:00
Recep Aslantas 8cb98357de stbi: fix thread local selector
* GCC < 5 supports __thread and GCC >= 5 supports C11 with _Thread_local
* Skip _Thread_local for MSVC because it may not be supported
2020-05-26 00:03:46 +03:00
Randy d1d0e9fdb0 add fuzz target to Makefile 2020-05-11 08:59:07 +02:00
Randy 5a7af50fa5 remove stb_png_read_fuzzer.options 2020-05-11 08:47:45 +02:00
Randy 88062723ff rename fuzz target 2020-05-11 08:18:56 +02:00
Randy b75413f8a4 do not define STBI_ONLY_PNG in fuzz target 2020-05-11 08:18:15 +02:00
Randy 4bafa56899 rename fuzz target, add entry point 2020-05-11 05:48:25 +02:00
Pedro J. Estébanez 2d0faa4d26 stb_vorbis.c: Fix missing update to 64-bit alignment 2020-05-03 02:35:08 +02:00
Ryan C. Gordon c29138ba59 Add randy408 to the "Bug warnings & fixes" list. 2020-04-29 14:20:33 -04:00
Randy 29d639546d fix integer arithmetic in stbi__zexpand() 2020-04-29 14:19:01 -04:00
Ryan C. Gordon b09cb2c6f5 Add Ryan C. Gordon to "Bug & warning fixes" contribution list. 2020-04-28 13:28:45 -04:00
Ryan C. Gordon 89f3f35c9f stbi__skip should return immediately if skipping zero bytes.
Otherwise we might waste time or throw away state in the i/o callbacks.
2020-04-28 13:28:45 -04:00
Ryan C. Gordon d60594847e Reject images that are too large (as defined by the application).
The BMP loader already had this hardcoded to (1 << 24) pixels, so this seems
like a good default to apply to all formats, but many apps will want to clamp
this much much lower.

It's possible to craft malicious but valid images that are enormous, causing
stb_image to allocate tons of memory and eat a ton of CPU, so locking these
to a maximum permitted size can save a lot of headaches in the wild.
2020-04-28 13:28:45 -04:00
Ryan C. Gordon 98ca24b8c7 Turn several asserts into formal checks.
There are several places where stb_image protects itself from bad data with
STBI_ASSERT macros, but if these are compiled out in release builds the code
will overflow buffers, etc, without warning. If they are left enabled, the
process will crash from assertion failures.

This patch attempts to leave the assertions in place that are meant to verify
the correctness of the interfaces (if the calling function was meant to pass
only 8 or 16 for bit depth, it's reasonable to assert that is accurate), but
changes asserts that are triggered by corrupt or malicious image file data.

Failed asserts were the majority of crashes during fuzzing; now all of these
cases safely report an error back to the calling app.
2020-04-28 13:28:45 -04:00
Ryan C. Gordon 95560bc6cf Be more aggressive about unexpected EOF conditions.
Fixes several hangs in the presence of bad input data.
2020-04-28 13:28:45 -04:00
Ryan C. Gordon eb4b057f0d Check a return value for errors.
Catches bad input data found during fuzzing.
2020-04-28 13:28:45 -04:00
Ryan C. Gordon b5d2296d5d Check for some obviously bad inputs from corrupt/malicious data.
These all caused crashes during fuzzing.
2020-04-28 13:28:45 -04:00
Ryan C. Gordon 385b5d3cda stbi__stdio_eof() should check ferror(), too.
Otherwise with filesystem errors, you might end up with a short read but
believe there's still more to read from the file, causing infinite loops.
2020-04-28 13:25:57 -04:00
Ryan C. Gordon 00f3f01be3 fseek() resets the EOF flag, even if seeking past the end of a read-only file.
This causes problems when stb_image tries to do this with stdio callbacks with
a maliciously crafted file (or just an unfortunately corrupt one)...

    // calls fread(), sets EOF flag, sets s->read_from_callbacks = 0
    stbi__refill_buffer(s);

    // calls fseek(), which resets the stream's EOF flag
    stbi__skip(some value we just read)

    // calls feof(), which always returns false because EOF flag was reset.
    while (!stbi__at_eof(s)) {
        // never calls fread() because s->read_from_callbacks==0
        stbi__refill_buffer(s);
        // loop forever
    }

To work around this, after seeking, we call fgetc(), which will set the EOF
flag as appropriate, and if not at EOF, we ungetc the byte so future reads
are correct. This fixes the infinite loop.
2020-04-28 13:25:57 -04:00
Clownacy d8df5e9974 Add myself to the list of contributors
The pull-request template says to do so.
2020-04-24 18:46:28 +01:00
Clownacy 47a3c4f5b5 stb_vorbis.c - Detect `__NEWLIB__` for `alloca.h`
This is needed for `stb_vorbis.c` to compile for the Wii U using
devkitPro.

This should theoretically also fix compilation for the Nintendo
Switch, 3DS, and Wii (with devkitPro, that is) as they all also use
Newlib.

Newlib is also used by Cygwin:
https://cygwin.com/git/?p=newlib-cygwin.git;a=blob;f=newlib/libc/include/alloca.h;h=5d36318914282280b353aed457e1b1f64947b584;hb=HEAD

And the Google Native Client:
https://chromium.googlesource.com/native_client/nacl-newlib/+/refs/heads/master/newlib/libc/include/alloca.h

As you can see from these links, these both provide `alloca.h` as
well, so it appears to be a safe guarantee that `alloca.h` is
available on Newlib.
2020-04-24 18:34:59 +01:00
Adam Korczynski fdec118312 Added fuzzer for stb_c_lexer 2020-04-09 16:21:56 +01:00
Ignacio Castano c7cf85ffce Integrate more accurate index selection by Rich Geldreich. 2020-04-05 20:37:29 -07:00
Kyle Langley 385b65da00
remove + 1 from stb_strscpy and offset of -1 (n--) in readdir_raw
Fix to buffer issue where stb_strscpy would use + 1 for buffer length when stb_p_strcpy_s is called, causing a stack variable corrupted issue.
Fix to readdir_raw to no longer account for stb_strscpy having + 1 in buffer length.
2020-03-30 22:18:40 -04:00
Andreas Molzer b67dabed2a
Add arraddn back with void return and deprecated 2020-03-25 20:58:57 +01:00
Andreas Molzer e485c7d353 Split arraddn into pointer and index return 2020-03-25 20:12:21 +01:00
Zack Middleton e919bcd32e stb_image: fix assert failing when loading BMP
This fixes two issues with an assert failing. I tested that the
first part fixes #909 and the second fixes #897.

1. Loading 16/24/32-bit BMP from memory caused an assert to fail
(excluding 16-bit BMP with hsz 12).

img_buffer offset was always compared with the buffer for
stbi_load_from_file() but stbi_load_from_memory() uses an external
buffer.

Resolution: Change s->buffer_start to s->img_buffer_original.

2. Loading BMP with large header from file caused assert to fail.

img_buffer points to stbi_uc buffer_start[128] but the largest BMP
supported has a 138 byte header (hsz 124) causing img_buffer to wrap
around to an offset of 10. The assert fails because 138 (header size)
!= 10 (offset in temp read buffer).

Resolution: Add the previously read bytes to the offset in temp read
buffer to get the absolute offset.

The issues were introduced by the commit c440a53d06
("stb_image: fix reading BMP with explicit masks").
2020-03-24 21:53:08 -04:00
wph612 2e78eb603b
Added debugging check on line 1604
I added the code assert(f->valid_bits >= n);  instead of removing if (f->valid_bits < 0) return 0; to improve code with checking and debugging instead.
2020-03-24 20:49:40 -04:00
wph612 fcd0a0bfaa
Remove if (f->valid_bits < 0) return 0; on line 1603
I propose to remove this line because  f->valid_bits will never be less than zero since, in the while loop, you're adding 8 to it. Therefore, it will always evaluate to false. This is to help remove redundant code.
2020-03-24 19:47:18 -04:00
Andreas Molzer e423b41e74
Fix arraddn returning index instead of pointer
The documentation of that operation already said:
> Returns a pointer to the first uninitialized item added.

This also makes a lot of sense, allowing easy initialization. But the
implementation returned the index of the first uninitialized element
instead.
2020-03-24 15:37:24 +01:00
Ignacio Castano 254e1c9975 Perfect quantization of DXT endpoints
A small change to quantize floating point endpoints to RGB565 as expanded in the DXT spec. For more info see: https://gist.github.com/castano/c92c7626f288f9e99e158520b14a61cf
2020-03-19 23:23:36 -07:00
David Reid 1d35dc8609 stb_vorbis: Fix macro redefinition warning on MinGW. 2020-02-15 07:23:22 +10:00
Luca Sas c5102ecc4d Refactored stbi__load_gif_main to use STBI_REALLOC_SIZED instead of STBI_REALLOC. 2020-02-13 13:05:12 +00:00
hashitaku 2e8b2d7f58 stb_ds.h: fix unused parameter warning 2020-02-08 10:11:40 +09:00
Sean Barrett a2c91804a3 stb_sprintf: avoid clang -O3 misaligned access 2020-02-06 05:36:53 -08:00
Sean Barrett f54acd4e13 Merge branch 'working' 2020-02-05 04:32:20 -08:00
Sean Barrett 828e6cfdf7 update test 2020-02-05 04:31:55 -08:00
Sean Barrett 95671cca57 update version number 2020-02-05 03:41:17 -08:00
Sean Barrett cd742941e6 stb_truetype: fix warning 2020-02-05 03:40:17 -08:00
Sean Barrett 37b9b20fde update version numbers 2020-02-05 03:19:08 -08:00
Sean Barrett efdaadcb4a Merge branch 'master' of https://github.com/MarcoLizza/stb into working 2020-02-05 03:16:46 -08:00
Sean Barrett 2805fe39ab Merge branch 'fix_ub_shift' of https://github.com/wojdyr/stb into working 2020-02-05 03:15:56 -08:00
Sean Barrett cb9d4e9547 sprintf: warning fixes 2020-02-05 03:15:41 -08:00
Sean Barrett 6b38abed1f Merge branch 'mine/avoid_warning' of https://github.com/wojdyr/stb into working 2020-02-05 03:10:20 -08:00
Sean Barrett f06f586d18 sprintf warnings 2020-02-05 03:10:07 -08:00
Marco Lizza 41a6bb58d1 Other (pedantic) warnings for possible uninitialized variables. 2020-02-04 17:03:48 +01:00
Marco Lizza 43c6bd4e0e Fixing (pedantic) cast warnings. 2020-02-04 17:03:23 +01:00