-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from boostorg/more_fuzz
Fuzz `to_chars` for integers
- Loading branch information
Showing
5 changed files
with
583 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2024 Matt Borland | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#include <boost/charconv.hpp> | ||
#include <boost/core/detail/string_view.hpp> | ||
#include <iostream> | ||
#include <exception> | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, std::size_t size) | ||
{ | ||
try | ||
{ | ||
auto c_data = reinterpret_cast<const char*>(data); | ||
|
||
for (int base = 2; base < 36; ++base) | ||
{ | ||
char buffer[10]; // Small enough it should force overflows | ||
|
||
char c_val {}; | ||
boost::charconv::from_chars(c_data, c_data + size, c_val, base); | ||
boost::charconv::to_chars(buffer, buffer + sizeof(buffer), c_val, base); | ||
|
||
int i_val {}; | ||
boost::charconv::from_chars(c_data, c_data + size, i_val, base); | ||
boost::charconv::to_chars(buffer, buffer + sizeof(buffer), i_val, base); | ||
|
||
long l_val {}; | ||
boost::charconv::from_chars(c_data, c_data + size, l_val, base); | ||
boost::charconv::to_chars(buffer, buffer + sizeof(buffer), l_val, base); | ||
|
||
long long ll_val {}; | ||
boost::charconv::from_chars(c_data, c_data + size, ll_val, base); | ||
boost::charconv::to_chars(buffer, buffer + sizeof(buffer), ll_val, base); | ||
|
||
unsigned char uc_val {}; | ||
boost::charconv::from_chars(c_data, c_data + size, uc_val, base); | ||
boost::charconv::to_chars(buffer, buffer + sizeof(buffer), uc_val, base); | ||
|
||
unsigned int ui_val {}; | ||
boost::charconv::from_chars(c_data, c_data + size, ui_val, base); | ||
boost::charconv::to_chars(buffer, buffer + sizeof(buffer), ui_val, base); | ||
|
||
unsigned long ul_val {}; | ||
boost::charconv::from_chars(c_data, c_data + size, ul_val, base); | ||
boost::charconv::to_chars(buffer, buffer + sizeof(buffer), ul_val, base); | ||
|
||
unsigned long long ull_val {}; | ||
boost::charconv::from_chars(c_data, c_data + size, ull_val, base); | ||
boost::charconv::to_chars(buffer, buffer + sizeof(buffer), ull_val, base); | ||
} | ||
} | ||
catch(...) | ||
{ | ||
std::cerr << "Error with: " << data << std::endl; | ||
std::terminate(); | ||
} | ||
|
||
return 0; | ||
} |
Binary file added
BIN
+70 Bytes
fuzzing/old_crashes/to_chars_int/crash-4b0b4ca7b862f00f7cd4c015af733b8ff83b4357
Binary file not shown.
Binary file added
BIN
+31 Bytes
fuzzing/old_crashes/to_chars_int/crash-bd2f2ecb3cea66ed93a8e24d4e14913486ff8eaf
Binary file not shown.
Oops, something went wrong.