8000
Skip to content

add fuzzers for chrono timepoint and localtime,gmtime#2469

Merged
vitaut merged 5 commits intofmtlib:masterfrom
pauldreik:add_localtime_and_timeopint_fuzzers
Aug 29, 2021
Merged

add fuzzers for chrono timepoint and localtime,gmtime#2469
vitaut merged 5 commits intofmtlib:masterfrom
pauldreik:add_localtime_and_timeopint_fuzzers

Conversation

@pauldreik
Copy link
Copy Markdown
Contributor

This adds fuzzers for previously unfuzzed parts of the fmt api. I have run them locally without finding anything.

Comment on lines +39 to +42
case 1:
// won't compile
// doit<std::chrono::steady_clock>(data,size);
8000 break;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't it compile?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the below compile error, so I just assumed it was not supported.

../include/fmt/core.h:1592:3: error: static_assert failed due to requirement '!std::is_same<const fmt::v8::detail::unformattable &, const fmt::v8::detail::unformattable &>::value' "Cannot format an argument. To make type T formattable provide a formatter<T> specialization: https://fmt.dev/latest/api.html#udt"
  static_assert(
  ^
../include/fmt/core.h:1718:23: note: in instantiation of function template specialization 'fmt::v8::detail::make_arg<true, fmt::v8::basic_format_context<fmt::v8::appender, char>, fmt::v8::detail::type::custom_type, std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1, 1000000000>>> &, 0>' requested here
        data_{detail::make_arg<
                      ^
../include/fmt/core.h:1737:10: note: in instantiation of function template specialization 'fmt::v8::format_arg_store<fmt::v8::basic_format_context<fmt::v8::appender, char>, std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1, 1000000000>>>>::format_arg_store<std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1, 1000000000>>> &>' requested here
  return {std::forward<Args>(args)...};
         ^
../include/fmt/core.h:2913:28: note: in instantiation of function template specialization 'fmt::v8::make_format_args<fmt::v8::basic_format_context<fmt::v8::appender, char>, std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1, 1000000000>>> &>' requested here
  return vformat(fmt, fmt::make_format_args(args...));
                           ^
../test/fuzzing/chrono-timepoint.cc:25:30: note: in instantiation of function template specialization 'fmt::v8::format<std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1, 1000000000>>> &>' requested here
  std::string message = fmt::format(format_str.get(), timepoint);
                             ^
../test/fuzzing/chrono-timepoint.cc:41:7: note: in instantiation of function template specialization 'doit<std::chrono::_V2::steady_clock>' requested here
      doit<std::chrono::steady_clock>(data,size);
      ^
In file included from ../test/fuzzing/chrono-timepoint.cc:3:
In file included from ../include/fmt/chrono.h:17:
In file included from ../include/fmt/format.h:44:
../include/fmt/core.h:1202:14: error: call to deleted constructor of 'fmt::v8::detail::fallback_formatter<fmt::v8::detail::unformattable, char, void>'
    auto f = Formatter();
             ^
../include/fmt/core.h:1189:21: note: in instantiation of function template specialization 'fmt::v8::detail::value<fmt::v8::basic_format_context<fmt::v8::appender, char>>::format_custom_arg<fmt::v8::detail::unformattable, fmt::v8::detail::fallback_formatter<fmt::v8::detail::unformattable, char, void>>' requested here
    custom.format = format_custom_arg<
                    ^
../test/fuzzing/chrono-timepoint.cc:25:30: note: in instantiation of function template specialization 'fmt::v8::format<std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1, 1000000000>>> &>' requested here
  std::string message = fmt::format(format_str.get(), timepoint);
                             ^
../test/fuzzing/chrono-timepoint.cc:41:7: note: in instantiation of function template specialization 'doit<std::chrono::_V2::steady_clock>' requested here
      doit<std::chrono::steady_clock>(data,size);
      ^
../include/fmt/core.h:979:3: note: 'fallback_formatter' has been explicitly marked deleted here
  fallback_formatter() = delete;
  ^
2 errors generated.
ninja: build stopped: subcommand failed.

mutating the first byte of the input now always results in picking
on of the two paths. Before, two of the four possible outcomes resulted
in doit() not being invoked.
@pauldreik pauldreik force-pushed the add_localtime_and_timeopint_fuzzers branch from 5c47d1b to a8f8e76 Compare August 29, 2021 13:02
@pauldreik
Copy link
Copy Markdown
Contributor Author

followed your requests, rebased and force pushed.

@vitaut vitaut merged commit 4db5723 into fmtlib:master Aug 29, 2021
PoetaKodu pushed a commit to pacc-repo/fmt that referenced this pull request Nov 11, 2021
* add fuzzers for chrono timepoint and localtime,gmtime

* reorder cases to improve throughput

mutating the first byte of the input now always results in picking
on of the two paths. Before, two of the four possible outcomes resulted
in doit() not being invoked.

* drop the localtime fuzzer

* inline aliases

* only fuzz std::chrono::system_clock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0