Skip to content

Commit

Permalink
prevent excessive time (found by oss-fuzz)
Browse files Browse the repository at this point in the history
the following triggered this:
std::string message =
      fmt::format("\377{:.214718908}\377", fmt::arg("/\0", 0.f));

there are probably more places with calls to fill_n which could be checked
  • Loading branch information
pauldreik committed May 10, 2019
1 parent 9a91093 commit b1d70b6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,12 @@ It grisu_prettify(const char* digits, int size, int exp, It it,
int num_zeros = (std::max)(params.num_digits - full_exp, 1);
if (params.trailing_zeros) {
*it++ = static_cast<Char>('.');
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
//avoid getting stuck here
if(num_zeros>100000) {
throw std::runtime_error("fuzz mode - avoiding excessive memory");
}
#endif
it = std::fill_n(it, num_zeros, static_cast<Char>('0'));
}
} else if (full_exp > 0) {
Expand Down

0 comments on commit b1d70b6

Please sign in to comment.