mirror of
https://github.com/webmproject/libwebp.git
synced 2025-04-05 00:16:50 +02:00
enc_dec_fuzzer: use WebPDecode()
rather than WebPDecodeRGBA(). This allows finer grained error detection and avoids an abort() when running under the nallocfuzz engine. Change-Id: I8ff37f2fe7e1c8b39bd4a8bfe7b26ac41149ba42
This commit is contained in:
parent
0fcb311cfc
commit
0081693d61
@ -100,18 +100,34 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* const data, size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try decoding the result.
|
// Try decoding the result.
|
||||||
int w, h;
|
|
||||||
const uint8_t* const out_data = memory_writer.mem;
|
const uint8_t* const out_data = memory_writer.mem;
|
||||||
const size_t out_size = memory_writer.size;
|
const size_t out_size = memory_writer.size;
|
||||||
uint8_t* const rgba = WebPDecodeBGRA(out_data, out_size, &w, &h);
|
WebPDecoderConfig dec_config;
|
||||||
if (rgba == nullptr || w != pic.width || h != pic.height) {
|
if (!WebPInitDecoderConfig(&dec_config)) {
|
||||||
fprintf(stderr, "WebPDecodeBGRA failed.\n");
|
fprintf(stderr, "WebPInitDecoderConfig failed.\n");
|
||||||
WebPFree(rgba);
|
|
||||||
WebPMemoryWriterClear(&memory_writer);
|
WebPMemoryWriterClear(&memory_writer);
|
||||||
WebPPictureFree(&pic);
|
WebPPictureFree(&pic);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dec_config.output.colorspace = MODE_BGRA;
|
||||||
|
const VP8StatusCode status = WebPDecode(out_data, out_size, &dec_config);
|
||||||
|
if ((status != VP8_STATUS_OK && status != VP8_STATUS_OUT_OF_MEMORY &&
|
||||||
|
status != VP8_STATUS_USER_ABORT) ||
|
||||||
|
(status == VP8_STATUS_OK && (dec_config.output.width != pic.width ||
|
||||||
|
dec_config.output.height != pic.height))) {
|
||||||
|
fprintf(stderr, "WebPDecode failed. status: %d.\n", status);
|
||||||
|
WebPFreeDecBuffer(&dec_config.output);
|
||||||
|
WebPMemoryWriterClear(&memory_writer);
|
||||||
|
WebPPictureFree(&pic);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status == VP8_STATUS_OK) {
|
||||||
|
const uint8_t* const rgba = dec_config.output.u.RGBA.rgba;
|
||||||
|
const int w = dec_config.output.width;
|
||||||
|
const int h = dec_config.output.height;
|
||||||
|
|
||||||
// Compare the results if exact encoding.
|
// Compare the results if exact encoding.
|
||||||
if (pic.use_argb && config.lossless && config.near_lossless == 100) {
|
if (pic.use_argb && config.lossless && config.near_lossless == 100) {
|
||||||
const uint32_t* src1 = (const uint32_t*)rgba;
|
const uint32_t* src1 = (const uint32_t*)rgba;
|
||||||
@ -128,7 +144,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* const data, size_t size) {
|
|||||||
}
|
}
|
||||||
if (v1 != v2) {
|
if (v1 != v2) {
|
||||||
fprintf(stderr, "Lossless compression failed pixel-exactness.\n");
|
fprintf(stderr, "Lossless compression failed pixel-exactness.\n");
|
||||||
WebPFree(rgba);
|
WebPFreeDecBuffer(&dec_config.output);
|
||||||
WebPMemoryWriterClear(&memory_writer);
|
WebPMemoryWriterClear(&memory_writer);
|
||||||
WebPPictureFree(&pic);
|
WebPPictureFree(&pic);
|
||||||
abort();
|
abort();
|
||||||
@ -136,8 +152,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* const data, size_t size) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WebPFree(rgba);
|
WebPFreeDecBuffer(&dec_config.output);
|
||||||
WebPMemoryWriterClear(&memory_writer);
|
WebPMemoryWriterClear(&memory_writer);
|
||||||
WebPPictureFree(&pic);
|
WebPPictureFree(&pic);
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user