Procházet zdrojové kódy

Ignore large fuzzer inputs. (#1085)

Jon Meow před 4 roky
rodič
revize
c01634ac8f

+ 9 - 0
toolchain/lexer/tokenized_buffer_fuzzer.cpp

@@ -16,6 +16,15 @@ namespace Carbon::Testing {
 // NOLINTNEXTLINE: Match the documented fuzzer entry point declaration style.
 extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data,
                                       std::size_t size) {
+  // Ignore large inputs.
+  // TODO: Investigate replacement with an error limit. Content with errors on
+  // escaped quotes (`\"` repeated) have O(M * N) behavior for M errors in a
+  // file length N, so either that will need to also be fixed or M will need to
+  // shrink for large (1MB+) inputs.
+  // This also affects parse_tree_fuzzer.cpp.
+  if (size > 100000) {
+    return 0;
+  }
   auto source = SourceBuffer::CreateFromText(
       llvm::StringRef(reinterpret_cast<const char*>(data), size));
 

+ 6 - 0
toolchain/parser/parse_tree_fuzzer.cpp

@@ -18,6 +18,12 @@ namespace Carbon::Testing {
 // NOLINTNEXTLINE: Match the documented fuzzer entry point declaration style.
 extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data,
                                       std::size_t size) {
+  // Ignore large inputs.
+  // TODO: See tokenized_buffer_fuzzer.cpp.
+  if (size > 100000) {
+    return 0;
+  }
+
   auto source = SourceBuffer::CreateFromText(
       llvm::StringRef(reinterpret_cast<const char*>(data), size));