mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
1 parent
3474af988b
commit
43ca567205
3 files changed
+38
-6
No files matched your search
@@ -27,6 +27,30 @@ intentional_segfault() {
|
||||
*ptr = 0;
|
||||
}
|
||||
|
||||
static uint32_t //
|
||||
popcount32(uint32_t x) {
|
||||
static const uint8_t table[256] = {
|
||||
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, //
|
||||
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, //
|
||||
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, //
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, //
|
||||
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, //
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, //
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, //
|
||||
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, //
|
||||
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, //
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, //
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, //
|
||||
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, //
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, //
|
||||
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, //
|
||||
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, //
|
||||
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, //
|
||||
};
|
||||
return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
|
||||
table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
|
||||
}
|
||||
|
||||
// jenkins_hash_u32 implements
|
||||
// https://en.wikipedia.org/wiki/Jenkins_hash_function
|
||||
static uint32_t //
|
||||
@@ -68,15 +92,21 @@ llvmFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
|
||||
uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
|
||||
|
||||
// The ! means that closed will be true for (size == 0).
|
||||
const bool closed = !(1 & popcount32(hash0));
|
||||
|
||||
wuffs_base__io_buffer src =
|
||||
wuffs_base__ptr_u8__reader((uint8_t*)data, size, true);
|
||||
wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
|
||||
|
||||
const char* msg = fuzz(&src, hash);
|
||||
if (msg) {
|
||||
if (strnlen(msg, 2047) >= 2047) {
|
||||
msg = "fuzzlib: internal error: error message is too long";
|
||||
}
|
||||
if (strstr(msg, "internal error:")) {
|
||||
if (closed && strstr(msg, "base: short read")) {
|
||||
fprintf(stderr, "short read on a closed io_reader\n");
|
||||
intentional_segfault();
|
||||
} else if (strstr(msg, "internal error:")) {
|
||||
fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
|
||||
intentional_segfault();
|
||||
}
|
||||
|
||||
@@ -317,6 +317,9 @@ fuzz_complex(wuffs_base__io_buffer* full_src, uint64_t hash) {
|
||||
no_progress_count = 0;
|
||||
} else if (no_progress_count < 999) {
|
||||
no_progress_count++;
|
||||
} else if (!full_src->meta.closed &&
|
||||
(status.repr == wuffs_base__suspension__short_read)) {
|
||||
return wuffs_base__status__message(&status);
|
||||
} else {
|
||||
return "fuzz: internal error: no progress";
|
||||
}
|
||||
@@ -345,8 +348,6 @@ fuzz_complex(wuffs_base__io_buffer* full_src, uint64_t hash) {
|
||||
break;
|
||||
|
||||
} else if (status.repr == wuffs_base__suspension__short_read) {
|
||||
// Some Wuffs packages can yield "$short read" for a closed io_reader,
|
||||
// but Wuffs' cbor package does not.
|
||||
if (src.meta.closed) {
|
||||
return "fuzz: internal error: short read on a closed io_reader";
|
||||
}
|
||||
|
||||
@@ -338,6 +338,9 @@ fuzz_complex(wuffs_base__io_buffer* full_src, uint64_t hash) {
|
||||
no_progress_count = 0;
|
||||
} else if (no_progress_count < 999) {
|
||||
no_progress_count++;
|
||||
} else if (!full_src->meta.closed &&
|
||||
(status.repr == wuffs_base__suspension__short_read)) {
|
||||
return wuffs_base__status__message(&status);
|
||||
} else {
|
||||
return "fuzz: internal error: no progress";
|
||||
}
|
||||
@@ -366,8 +369,6 @@ fuzz_complex(wuffs_base__io_buffer* full_src, uint64_t hash) {
|
||||
break;
|
||||
|
||||
} else if (status.repr == wuffs_base__suspension__short_read) {
|
||||
// Some Wuffs packages can yield "$short read" for a closed io_reader,
|
||||
// but Wuffs' json package does not.
|
||||
if (src.meta.closed) {
|
||||
return "fuzz: internal error: short read on a closed io_reader";
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user