mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 08:32:11 +01:00
Have fuzzers handle a zero workbuf_len
This commit is contained in:
1 parent
bcbad690a4
commit
115612eb74
2 files changed
+26
-12
No files matched your search
+14
-8
@@ -75,15 +75,19 @@ const char* fuzz(wuffs_base__io_reader src_reader, uint32_t hash) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// Wuffs allows either statically or dynamically allocated work buffers.
|
||||
// This program exercises dynamic allocation.
|
||||
uint64_t n = wuffs_gif__decoder__workbuf_len(&dec).max_incl;
|
||||
if (n > 64 * 1024 * 1024) { // Don't allocate more than 64 MiB.
|
||||
ret = "image too large";
|
||||
goto exit;
|
||||
}
|
||||
workbuf = wuffs_base__malloc_slice_u8(malloc, n);
|
||||
if (!workbuf.ptr) {
|
||||
ret = "out of memory";
|
||||
goto exit;
|
||||
if (n > 0) {
|
||||
workbuf = wuffs_base__malloc_slice_u8(malloc, n);
|
||||
if (!workbuf.ptr) {
|
||||
ret = "out of memory";
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
n = wuffs_base__pixel_config__pixbuf_len(&ic.pixcfg);
|
||||
@@ -91,10 +95,12 @@ const char* fuzz(wuffs_base__io_reader src_reader, uint32_t hash) {
|
||||
ret = "image too large";
|
||||
goto exit;
|
||||
}
|
||||
pixbuf = wuffs_base__malloc_slice_u8(malloc, n);
|
||||
if (!pixbuf.ptr) {
|
||||
ret = "out of memory";
|
||||
goto exit;
|
||||
if (n > 0) {
|
||||
pixbuf = wuffs_base__malloc_slice_u8(malloc, n);
|
||||
if (!pixbuf.ptr) {
|
||||
ret = "out of memory";
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
wuffs_base__pixel_buffer pb = ((wuffs_base__pixel_buffer){});
|
||||
|
||||
@@ -48,8 +48,17 @@ It should print "PASS", amongst other information, and exit(0).
|
||||
#include "../../../release/c/wuffs-unsupported-snapshot.c"
|
||||
#include "../fuzzlib/fuzzlib.c"
|
||||
|
||||
#define DST_BUFFER_SIZE 65536
|
||||
|
||||
// Wuffs allows either statically or dynamically allocated work buffers. This
|
||||
// program exercises static allocation.
|
||||
#define WORK_BUFFER_SIZE WUFFS_ZLIB__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE
|
||||
#if WORK_BUFFER_SIZE > 0
|
||||
uint8_t work_buffer[WORK_BUFFER_SIZE];
|
||||
#else
|
||||
// Not all C/C++ compilers support 0-length arrays.
|
||||
uint8_t work_buffer[1];
|
||||
#endif
|
||||
|
||||
const char* fuzz(wuffs_base__io_reader src_reader, uint32_t hash) {
|
||||
wuffs_zlib__decoder dec = ((wuffs_zlib__decoder){});
|
||||
@@ -64,12 +73,11 @@ const char* fuzz(wuffs_base__io_reader src_reader, uint32_t hash) {
|
||||
// verify that checksumming does not lead to e.g. buffer overflows.
|
||||
wuffs_zlib__decoder__set_ignore_checksum(&dec, hash & 0xFFFF);
|
||||
|
||||
const size_t dstbuf_size = 65536;
|
||||
uint8_t dstbuf[dstbuf_size];
|
||||
uint8_t dst_buffer[DST_BUFFER_SIZE];
|
||||
wuffs_base__io_buffer dst = ((wuffs_base__io_buffer){
|
||||
.data = ((wuffs_base__slice_u8){
|
||||
.ptr = dstbuf,
|
||||
.len = dstbuf_size,
|
||||
.ptr = dst_buffer,
|
||||
.len = DST_BUFFER_SIZE,
|
||||
}),
|
||||
});
|
||||
wuffs_base__io_writer dst_writer = wuffs_base__io_buffer__writer(&dst);
|
||||
|
||||
Reference in new issue
Block a user