From bc94cd68f8ad1ddbc5ffa946db590c7c997b62e7 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Wed, 5 May 2021 21:12:22 +0000 Subject: [PATCH] Interrupt fuzzer if invalid program is generated If a a valid shader is input into Tint an valid shader should be output, if the output is invalid then there is a bug in Tint. BUG=tint:721 Change-Id: Id3fe80eeb65fa55276d74e2f4868e276bd52ec86 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50000 Commit-Queue: Ryan Harrison Auto-Submit: Ryan Harrison Reviewed-by: Ben Clayton --- fuzzers/tint_common_fuzzer.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fuzzers/tint_common_fuzzer.cc b/fuzzers/tint_common_fuzzer.cc index e4a77c01ef..b47a3271bc 100644 --- a/fuzzers/tint_common_fuzzer.cc +++ b/fuzzers/tint_common_fuzzer.cc @@ -33,6 +33,15 @@ namespace fuzzers { __builtin_trap(); } +[[noreturn]] void ValidityErrorReporter() { + auto printer = tint::diag::Printer::create(stderr, true); + printer->write( + "Fuzzing detected valid input program being transformed into an invalid " + "output progam", + {diag::Color::kRed, true}); + __builtin_trap(); +} + bool ExtractBindingRemapperInputs(const uint8_t** data, size_t* size, tint::transform::DataMap* inputs) { @@ -244,7 +253,7 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) { if (transform_manager_) { auto out = transform_manager_->Run(&program, transform_inputs_); if (!out.program.IsValid()) { - return 0; + ValidityErrorReporter(); } program = std::move(out.program);