Added patches to zip.c to prevent OOM while fuzzing
Responding to https://github.com/kuba--/zip/pull/367#discussion_r1958774563
This PR adds a compiler definition specific to OSSFUZZ builds and bails prior to attempting to malloc beyond 1 gigabyte while fuzzing
@kuba-- See a proposed fix to what we were discussing above
I think the check is not where the real problem is. It happens IMO on zip_stream_open - when we open the compressed stream for reading (not a file).
https://github.com/kuba--/zip/blob/master/fuzz/read_entry_fuzzer.c#L10
Moreover, we can add those checks/asserts inside fuzz package.
@kuba-- Updated to reflect your suggestions!
Why fuzz_zip_validate_stream needs to be in the library? Cannot we put in some fuzz helpers?
zip library should be pure. Some people just include those three files into their project and they do really care about fuzz stuff.
@kuba-- I wrapped it in an ifdef so that it will only be included if they explicitly build for fuzzing. Do you have a suggestion as to how to move it into a helper?
It depends upon a fully defined zip_t struct, which is currently defined in zip.c
Can you take a look how fuzz was integrated into miniz (https://github.com/richgel999/miniz/tree/master). I think we should follow the same approach, because this library is based on miniz