animencoder_fuzzer: fix error check w/Nallocfuzz

WebPAnimEncoderAdd() may fail due to muxer errors that are reported as
booleans. When running under the nallocfuzz engine, ignore all failures.

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

Change-Id: I36589545d20ac30a67f7e09264146db085dee6ca
This commit is contained in:
James Zern 2023-07-21 22:40:41 +00:00
parent e94b36d66d
commit a71ce1cf74

View File

@ -109,7 +109,14 @@ int AddFrame(WebPAnimEncoder** const enc,
const WebPEncodingError error_code = pic.error_code; const WebPEncodingError error_code = pic.error_code;
WebPAnimEncoderDelete(*enc); WebPAnimEncoderDelete(*enc);
WebPPictureFree(&pic); WebPPictureFree(&pic);
if (error_code == VP8_ENC_ERROR_OUT_OF_MEMORY) return 0; // Tolerate failures when running under the nallocfuzz engine as
// WebPAnimEncoderAdd() may fail due to memory allocation errors outside of
// the encoder; in muxer functions that return booleans for instance.
if (error_code == VP8_ENC_ERROR_OUT_OF_MEMORY ||
error_code == VP8_ENC_ERROR_BAD_WRITE ||
getenv("NALLOC_FUZZ_VERSION") != nullptr) {
return 0;
}
fprintf(stderr, "WebPEncode failed. Error code: %d\n", error_code); fprintf(stderr, "WebPEncode failed. Error code: %d\n", error_code);
abort(); abort();
} }