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

Added patches to zip.c to prevent OOM while fuzzing #369

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

capuanob
Copy link
Contributor

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

@capuanob
Copy link
Contributor Author

@kuba-- See a proposed fix to what we were discussing above

@kuba--
Copy link
Owner

kuba-- commented Feb 18, 2025

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.

@capuanob
Copy link
Contributor Author

@kuba-- Updated to reflect your suggestions!

@kuba--
Copy link
Owner

kuba-- commented Feb 23, 2025

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.

@capuanob
Copy link
Contributor Author

@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

@kuba--
Copy link
Owner

kuba-- commented Feb 24, 2025

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

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.

2 participants