Skip to content

Commit

Permalink
move check for large precision values closer to where needed
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldreik committed Jun 29, 2019
1 parent ef6e23e commit 40a17be
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ template <> FMT_FUNC int count_digits<4>(internal::fallback_uintptr n) {
template <typename T>
int format_float(char* buf, std::size_t size, const char* format, int precision,
T value) {
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
if (precision > 100000) {
throw std::runtime_error("fuzz mode - avoid large allocation inside snprintf");
}
#endif
// Suppress the warning about nonliteral format string.
auto snprintf_ptr = FMT_SNPRINTF;
return precision < 0 ? snprintf_ptr(buf, size, format, value)
Expand Down Expand Up @@ -772,12 +777,6 @@ void sprintf_format(Double value, internal::buffer<char>& buf,
*format_ptr++ = type;
*format_ptr = '\0';

#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
if (spec.precision > 1000) {
throw std::runtime_error("fuzz mode - avoiding large precision");
}
#endif

// Format using snprintf.
char* start = nullptr;
for (;;) {
Expand Down

0 comments on commit 40a17be

Please sign in to comment.