Call initialize instead of check_wuffs_version

This commit is contained in:
Nigel Tao committed 2019-02-16 14:18:25 +11:00
1 parent b41f121d20
commit 53760ce0fd
7 files changed
+34 -18

No files matched your search

+2 -2
View File
@@ -58,8 +58,8 @@ for a C++ compiler $CXX, such as clang++ or g++.
uint8_t src_buffer[SRC_BUFFER_SIZE];
int main(int argc, char** argv) {
wuffs_crc32__ieee_hasher h = ((wuffs_crc32__ieee_hasher){});
const char* status = h.check_wuffs_version(sizeof h, WUFFS_VERSION);
wuffs_crc32__ieee_hasher h;
const char* status = h.initialize(sizeof h, WUFFS_VERSION, 0);
if (status) {
fprintf(stderr, "%s\n", status);
return 1;
+2 -2
View File
@@ -288,9 +288,9 @@ const char* allocate(wuffs_gif__decoder* dec, wuffs_base__image_config* ic) {
}
const char* play() {
wuffs_gif__decoder dec = ((wuffs_gif__decoder){});
wuffs_gif__decoder dec;
wuffs_base__status status =
wuffs_gif__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
wuffs_gif__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
if (status) {
return status;
}
+3 -2
View File
@@ -86,8 +86,9 @@ static const char* decode() {
if (!dec) {
return "out of memory";
}
const char* status = wuffs_deflate__decoder__check_wuffs_version(
dec, sizeof__wuffs_deflate__decoder(), WUFFS_VERSION);
const char* status = wuffs_deflate__decoder__initialize(
dec, sizeof__wuffs_deflate__decoder(), WUFFS_VERSION,
WUFFS_INITIALIZE__ALREADY_ZEROED);
if (status) {
free(dec);
return status;
+2 -2
View File
@@ -79,9 +79,9 @@ uint8_t work_buffer[WORK_BUFFER_SIZE];
static void ignore_return_value(int ignored) {}
static const char* decode() {
wuffs_gzip__decoder dec = ((wuffs_gzip__decoder){});
wuffs_gzip__decoder dec;
const char* status =
wuffs_gzip__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
wuffs_gzip__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
if (status) {
return status;
}
+5 -3
View File
@@ -56,9 +56,11 @@ const char* fuzz(wuffs_base__io_reader src_reader, uint32_t hash) {
// Use a {} code block so that "goto exit" doesn't trigger "jump bypasses
// variable initialization" warnings.
{
wuffs_gif__decoder dec = ((wuffs_gif__decoder){});
const char* status = wuffs_gif__decoder__check_wuffs_version(
&dec, sizeof dec, WUFFS_VERSION);
wuffs_gif__decoder dec;
const char* status = wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
(hash & 1) ? WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED
: 0);
if (status) {
ret = status;
goto exit;
+5 -4
View File
@@ -61,9 +61,10 @@ 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){});
const char* status =
wuffs_zlib__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
wuffs_zlib__decoder dec;
const char* status = wuffs_zlib__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
(hash & 1) ? WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED : 0);
if (status) {
return status;
}
@@ -71,7 +72,7 @@ const char* fuzz(wuffs_base__io_reader src_reader, uint32_t hash) {
// Ignore the checksum for 99.99%-ish of all input. When fuzzers generate
// random input, the checkum is very unlikely to match. Still, it's useful to
// verify that checksumming does not lead to e.g. buffer overflows.
wuffs_zlib__decoder__set_ignore_checksum(&dec, hash & 0xFFFF);
wuffs_zlib__decoder__set_ignore_checksum(&dec, hash & 0xFFFE);
uint8_t dst_buffer[DST_BUFFER_SIZE];
wuffs_base__io_buffer dst = ((wuffs_base__io_buffer){
+15 -3
View File
@@ -112,6 +112,14 @@ uint8_t idat_buffer[SRC_BUFFER_SIZE] = {0};
size_t idat_splits[MAX_IDAT_CHUNKS + 1] = {0};
uint32_t num_idat_chunks = 0;
#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
uint32_t width = 0;
uint32_t height = 0;
uint64_t bytes_per_pixel = 0;
@@ -218,9 +226,9 @@ const char* process_png_chunks(uint8_t* p, size_t n) {
}
const char* decode_once(bool frag_dst, bool frag_idat) {
wuffs_zlib__decoder dec = ((wuffs_zlib__decoder){});
wuffs_zlib__decoder dec;
const char* status =
wuffs_zlib__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
wuffs_zlib__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
if (status) {
return status;
}
@@ -259,7 +267,11 @@ const char* decode_once(bool frag_dst, bool frag_idat) {
while (true) {
status =
wuffs_zlib__decoder__decode_io_writer(&dec, dst_writer, idat_reader);
wuffs_zlib__decoder__decode_io_writer(&dec, dst_writer, idat_reader,
((wuffs_base__slice_u8){
.ptr = work_buffer,
.len = WORK_BUFFER_SIZE,
}));
if (!status) {
break;