Skip to content

Commit b1d70b6

Browse files
committed
prevent excessive time (found by oss-fuzz)
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
1 parent 9a91093 commit b1d70b6

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

include/fmt/format.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,12 @@ It grisu_prettify(const char* digits, int size, int exp, It it,
11871187
int num_zeros = (std::max)(params.num_digits - full_exp, 1);
11881188
if (params.trailing_zeros) {
11891189
*it++ = static_cast<Char>('.');
1190+
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
1191+
//avoid getting stuck here
1192+
if(num_zeros>100000) {
1193+
throw std::runtime_error("fuzz mode - avoiding excessive memory");
1194+
}
1195+
#endif
11901196
it = std::fill_n(it, num_zeros, static_cast<Char>('0'));
11911197
}
11921198
} else if (full_exp > 0) {

0 commit comments

Comments
 (0)