From 8800ba091dc9a8bcfd48b1188488a1db90833797 Mon Sep 17 00:00:00 2001 From: Alastair Donaldson Date: Wed, 21 Jul 2021 13:23:51 +0000 Subject: [PATCH] Fix assertion strings and tidy up memcpy call These changes were intended for submission as part of 58386. Change-Id: I23f7ada1e8940dce6855176724ade1f2bb7687f8 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/59024 Auto-Submit: Alastair Donaldson Kokoro: Kokoro Reviewed-by: Ryan Harrison Reviewed-by: Ben Clayton Commit-Queue: Alastair Donaldson --- fuzzers/tint_common_fuzzer.cc | 4 ++-- fuzzers/tint_spirv_tools_fuzzer/fuzzer.cc | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/fuzzers/tint_common_fuzzer.cc b/fuzzers/tint_common_fuzzer.cc index 88f0107dcf..590ff15dec 100644 --- a/fuzzers/tint_common_fuzzer.cc +++ b/fuzzers/tint_common_fuzzer.cc @@ -205,8 +205,8 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) { // sizeof(uint32_t)` uint32_t values. If `size` is not a multiple of // sizeof(uint32_t) then not all of `data` can be copied into // `spirv_input`, and any trailing bytes are discarded. - const size_t adjusted_size = (size / sizeof(uint32_t)) * sizeof(uint32_t); - std::memcpy(spirv_input.data(), data, adjusted_size); + std::memcpy(spirv_input.data(), data, + spirv_input.size() * sizeof(uint32_t)); if (spirv_input.empty()) { return 0; } diff --git a/fuzzers/tint_spirv_tools_fuzzer/fuzzer.cc b/fuzzers/tint_spirv_tools_fuzzer/fuzzer.cc index dac05dc918..6ca8b46fde 100644 --- a/fuzzers/tint_spirv_tools_fuzzer/fuzzer.cc +++ b/fuzzers/tint_spirv_tools_fuzzer/fuzzer.cc @@ -102,7 +102,8 @@ extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* data, unsigned seed) { assert((size % 4) == 0 && "A valid SPIR-V binary's size must be a multiple of 4, and the " - "SPIR-V Tools fuzzer should only work with valid binaries."); + "SPIR-V Tools fuzzer should only work with valid binaries. Check that " + "the fuzzer has been correctly configured."); std::vector binary(size / sizeof(uint32_t)); std::memcpy(binary.data(), data, size); @@ -175,8 +176,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { } assert((size % 4) == 0 && - "A valid SPIR-V binary's size is a multiple of 4 bytes, and the " - "SPIR-V Tools fuzzer should only work with valid binaries."); + "By design, the SPIR-V Tools fuzzer should only ever test using valid " + "SPIR-V binaries, whose sizes should be multiples of 4 bytes. Check " + "that the fuzzer has been configured correctly, with a corpus of " + "valid SPIR-V binaries, and with only the custom mutator enabled."); CommonFuzzer spv_to_wgsl(InputFormat::kSpv, OutputFormat::kWGSL); spv_to_wgsl.EnableInspector();