diff --git a/fuzzers/tint_common_fuzzer.h b/fuzzers/tint_common_fuzzer.h index 32475cccc6..c6e8dcca7f 100644 --- a/fuzzers/tint_common_fuzzer.h +++ b/fuzzers/tint_common_fuzzer.h @@ -45,15 +45,16 @@ class Reader { template std::vector vector() { auto count = read(); - if (failed_ || size_ < count) { + auto size = static_cast(count) * sizeof(T); + if (failed_ || size_ < size) { mark_failed(); return {}; } std::vector out(count); if (!out.empty()) { - memcpy(out.data(), data_, count * sizeof(T)); - data_ += count * sizeof(T); - size_ -= count * sizeof(T); + memcpy(out.data(), data_, size); + data_ += size; + size_ -= size; } return out; } @@ -61,13 +62,15 @@ class Reader { template std::vector vector(T (*extract)(Reader*)) { auto count = read(); - if (size_ < count) { - mark_failed(); + if (failed_) { return {}; } std::vector out(count); for (uint8_t i = 0; i < count; i++) { out[i] = extract(this); + if (failed_) { + return {}; + } } return out; }