diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 7d6aeb2a..0f080386 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -1151,10 +1151,10 @@ int snprintf_float(T value, int precision, float_specs specs, for (;;) { auto begin = buf.data() + offset; auto capacity = buf.capacity() - offset; -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION +#ifdef FUZZ_MODE if (precision > 100000) - FMT_THROW(std::runtime_error( - "fuzz mode - avoid large allocation inside snprintf")); + throw std::runtime_error( + "fuzz mode - avoid large allocation inside snprintf"); #endif // Suppress the warning about a nonliteral format string. // Cannot use auto becase of a bug in MinGW (#1532). diff --git a/include/fmt/format.h b/include/fmt/format.h index f6054b74..d28e4295 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -699,8 +699,8 @@ class basic_memory_buffer : public internal::buffer { template void basic_memory_buffer::grow(std::size_t size) { -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - if (size > 1000) FMT_THROW(std::runtime_error("fuzz mode - won't grow that much")); +#ifdef FUZZ_MODE + if (size > 1000) throw std::runtime_error("fuzz mode - won't grow that much"); #endif std::size_t old_capacity = this->capacity(); std::size_t new_capacity = old_capacity + old_capacity / 2; @@ -1136,9 +1136,9 @@ template class float_writer { *it++ = static_cast('0'); return it; } -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION +#ifdef FUZZ_MODE if (num_zeros > 1000) - FMT_THROW(std::runtime_error("fuzz mode - avoiding excessive cpu use")); + throw std::runtime_error("fuzz mode - avoiding excessive cpu use"); #endif it = std::fill_n(it, num_zeros, static_cast('0')); } diff --git a/src/format.cc b/src/format.cc index 1f2dabf3..d9ca9134 100644 --- a/src/format.cc +++ b/src/format.cc @@ -13,10 +13,10 @@ namespace internal { template int format_float(char* buf, std::size_t size, const char* format, int precision, T value) { -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION +#ifdef FUZZ_MODE if (precision > 100000) - FMT_THROW(std::runtime_error( - "fuzz mode - avoid large allocation inside snprintf")); + throw std::runtime_error( + "fuzz mode - avoid large allocation inside snprintf"); #endif // Suppress the warning about nonliteral format string. int (*snprintf_ptr)(char*, size_t, const char*, ...) = FMT_SNPRINTF; diff --git a/test/fuzzing/README.md b/test/fuzzing/README.md index d8e20849..b3f1829f 100644 --- a/test/fuzzing/README.md +++ b/test/fuzzing/README.md @@ -7,14 +7,19 @@ in fmt. It is a part of the continous fuzzing at The source code is modified to make the fuzzing possible without locking up on resource exhaustion: ```cpp -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION +#ifdef FUZZ_MODE if(spec.precision>100000) { - FMT_THROW(std::runtime_error("fuzz mode - avoiding large precision")); + throw std::runtime_error("fuzz mode - avoiding large precision"); } #endif -``` -This macro is the defacto standard for making fuzzing practically possible, see -[the libFuzzer documentation](https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode). +``` +This macro `FUZZ_MODE` is enabled on OSS-Fuzz builds and makes fuzzing +practically possible. It is used in fmt code to prevent resource exhaustion in +fuzzing mode. +The macro `FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION` is the +defacto standard for making fuzzing practically possible to disable certain +fuzzing-unfriendly features (for example, randomness), see [the libFuzzer +documentation](https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode). ## Running the fuzzers locally