enc_dec_fuzzer: fix WebPEncode/pic.error_code check

pic.error_code may be set to VP8_ENC_ERROR_BAD_WRITE if the writer fails
due to a memory allocation failure.

Found by Nallocfuzz (https://github.com/catenacyber/nallocfuzz).

Change-Id: I912c9e5f9a37b78832c52d9ab6f0710967fbadac
This commit is contained in:
James Zern 2023-07-18 23:01:36 +00:00
parent 982c177c8a
commit 0fcb311cfc

View File

@ -91,7 +91,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* const data, size_t size) {
const WebPEncodingError error_code = pic.error_code; const WebPEncodingError error_code = pic.error_code;
WebPMemoryWriterClear(&memory_writer); WebPMemoryWriterClear(&memory_writer);
WebPPictureFree(&pic); WebPPictureFree(&pic);
if (error_code == VP8_ENC_ERROR_OUT_OF_MEMORY) return 0; if (error_code == VP8_ENC_ERROR_OUT_OF_MEMORY ||
error_code == VP8_ENC_ERROR_BAD_WRITE) {
return 0;
}
fprintf(stderr, "WebPEncode failed. Error code: %d\n", error_code); fprintf(stderr, "WebPEncode failed. Error code: %d\n", error_code);
abort(); abort();
} }