diff --git a/projects/abseil-cpp/BUILD b/projects/abseil-cpp/BUILD index 4a8fd0baa6b7..9200d393eccc 100644 --- a/projects/abseil-cpp/BUILD +++ b/projects/abseil-cpp/BUILD @@ -39,3 +39,92 @@ cc_fuzz_test( "@com_google_absl//absl/base:base", ], ) + +cc_fuzz_test( + name = "format_arg_fuzzer", + srcs = ["format_arg_fuzzer.cc"], + deps = ["@com_google_absl//absl/strings:str_format"], +) + +cc_fuzz_test( + name = "safe_strto128_fuzzer", + srcs = ["safe_strto128_fuzzer.cc"], + deps = [ + "@com_google_absl//absl/numeric:int128", + "@com_google_absl//absl/strings", + ], +) + +cc_fuzz_test( + name = "format_parser_fuzzer", + srcs = ["format_parser_fuzzer.cc"], + deps = [ + "@com_google_absl//absl/strings:str_format", + "@com_google_absl//absl/strings:string_view", + ], +) + +cc_fuzz_test( + + name = "format_summarize_fuzzer", + srcs = ["format_summarize_fuzzer.cc"], + deps = [ + "@com_google_absl//absl/strings:str_format", + ], +) + +cc_fuzz_test( + name = "format_arg_dispatch_fuzzer", + srcs = ["format_arg_dispatch_fuzzer.cc"], + deps = ["@com_google_absl//absl/strings:str_format"], +) + +cc_fuzz_test( + name = "invoke_object_fuzzer", + srcs = ["invoke_object_fuzzer.cc"], + deps = [ + "@com_google_absl//absl/functional:function_ref", + ], +) + +cc_fuzz_test( + name = "strcontains_ignorecase_fuzzer", + srcs = ["strcontains_ignorecase_fuzzer.cc"], + deps = [ + "@com_google_absl//absl/strings", + ], +) + +cc_fuzz_test( + name = "bigunsigned_constructor_fuzzer", + srcs = ["bigunsigned_constructor_fuzzer.cc"], + deps = [ + "@com_google_absl//absl/strings", + ], +) + +cc_fuzz_test( + name = "int128_ostream_fuzzer", + srcs = ["int128_ostream_fuzzer.cc"], + deps = [ + "@com_google_absl//absl/numeric:int128", + ], +) + +cc_fuzz_test( + name = "parsed_format_base_fuzzer", + srcs = ["parsed_format_base_fuzzer.cc"], + deps = [ + "@com_google_absl//absl/strings:str_format", + "@com_google_absl//absl/strings:string_view", + ], +) + +cc_fuzz_test( + name = "format_wchar_fuzzer", + srcs = ["format_wchar_fuzzer.cc"], + deps = [ + "@com_google_absl//absl/strings:str_format", + "@com_google_absl//absl/strings:string_view", + ], +) diff --git a/projects/abseil-cpp/bigunsigned_constructor_fuzzer.cc b/projects/abseil-cpp/bigunsigned_constructor_fuzzer.cc new file mode 100644 index 000000000000..2a2d731db123 --- /dev/null +++ b/projects/abseil-cpp/bigunsigned_constructor_fuzzer.cc @@ -0,0 +1,61 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include +#include + +#include "absl/strings/string_view.h" +#include "absl/strings/internal/charconv_bigint.h" + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + FuzzedDataProvider provider(data, size); + + // Test with decimal number + std::string numeric_str( + provider.ConsumeIntegralInRange(1, 20), + provider.PickValueInArray({'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}) + ); + absl::strings_internal::BigUnsigned<4> numeric_num(numeric_str); + numeric_num.ToString(); + + // Test with maximum digits + std::string max_str(absl::strings_internal::BigUnsigned<4>::Digits10(), '9'); + absl::strings_internal::BigUnsigned<4> max_num(max_str); + max_num.ToString(); + + // Test with mixed chars + std::string mixed_str( + provider.ConsumeIntegralInRange(1, 20), + provider.PickValueInArray({'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'}) + ); + absl::strings_internal::BigUnsigned<4> mixed_num(mixed_str); + mixed_num.ToString(); + + // Test empty string + absl::strings_internal::BigUnsigned<4> empty_num(""); + empty_num.ToString(); + + // Test non-digit string + std::string non_digit_str( + provider.ConsumeIntegralInRange(1, 20), + provider.ConsumeIntegralInRange('a', 'z') + ); + absl::strings_internal::BigUnsigned<4> non_digit_num(non_digit_str); + non_digit_num.ToString(); + + return 0; +} diff --git a/projects/abseil-cpp/format_arg_dispatch_fuzzer.cc b/projects/abseil-cpp/format_arg_dispatch_fuzzer.cc new file mode 100644 index 000000000000..57eab979d238 --- /dev/null +++ b/projects/abseil-cpp/format_arg_dispatch_fuzzer.cc @@ -0,0 +1,76 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include +#include +#include "absl/strings/str_format.h" + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + FuzzedDataProvider provider(data, size); + std::string output; + + // Integers + int int_val = provider.ConsumeIntegral(); + unsigned int uint_val = provider.ConsumeIntegral(); + int64_t int64_val = provider.ConsumeIntegral(); + uint64_t uint64_val = provider.ConsumeIntegral(); + + absl::StrFormat("%d%x%o%u%X%ld%lu", int_val, int_val, int_val, + uint_val, uint_val, int64_val, uint64_val); + + absl::StrFormat("%d%d%u", std::numeric_limits::max(), + std::numeric_limits::min(), + std::numeric_limits::max()); + + // Floating point + double double_val = provider.ConsumeFloatingPoint(); + absl::StrFormat("%f%e%g", double_val, double_val, double_val); + + static const double special_vals[] = { + std::numeric_limits::infinity(), + -std::numeric_limits::infinity(), + std::numeric_limits::quiet_NaN(), + std::numeric_limits::denorm_min(), + std::numeric_limits::min(), + std::numeric_limits::max() + }; + for (double val : special_vals) { + absl::StrFormat("%f%e%g", val, val, val); + } + + // Bool and char + bool bool_val = provider.ConsumeBool(); + char char_val = provider.ConsumeIntegral(); + absl::StrFormat("%d%v%c", bool_val, bool_val, char_val); + + static const char special_chars[] = { + '\0', '\n', '\t', '\r', '\\', '\'', '\"', '\x1F' + }; + for (char c : special_chars) { + absl::StrFormat("%c", c); + } + + // Strings and format flags + std::string str = provider.ConsumeRandomLengthString(); + absl::StrFormat("%s%10s%-10s", str.c_str(), str.c_str(), str.c_str()); + absl::StrFormat("%s", ""); + + // Format flags, width and precision + absl::StrFormat("%+d% d%-10d%010d%#x", int_val, int_val, int_val, int_val, int_val); + absl::StrFormat("%10.5f%.10f%15.10f", double_val, double_val, double_val); + + return 0; +} diff --git a/projects/abseil-cpp/format_arg_fuzzer.cc b/projects/abseil-cpp/format_arg_fuzzer.cc new file mode 100644 index 000000000000..9efc64ae4f1c --- /dev/null +++ b/projects/abseil-cpp/format_arg_fuzzer.cc @@ -0,0 +1,149 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include "absl/strings/str_format.h" + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + if (size < 4) return 0; + FuzzedDataProvider provider(data, size); + std::string result; + + // Test literal percent (was missing) + result = absl::StrFormat("%%"); + + // Test basic integer types with different formats and sizes + int value = provider.ConsumeIntegral(); + result = absl::StrFormat("%d", value); + result = absl::StrFormat("%i", value); + result = absl::StrFormat("%u", value); + result = absl::StrFormat("%x", value); + result = absl::StrFormat("%X", value); + result = absl::StrFormat("%o", value); + + // Test integers with length modifiers + result = absl::StrFormat("%hhd", value); + result = absl::StrFormat("%hd", value); + result = absl::StrFormat("%ld", value); + result = absl::StrFormat("%lld", value); + result = absl::StrFormat("%zd", value); + result = absl::StrFormat("%jd", value); + result = absl::StrFormat("%td", value); + + // Test different integer sizes + int8_t i8 = provider.ConsumeIntegral(); + result = absl::StrFormat("%d", i8); + + int16_t i16 = provider.ConsumeIntegral(); + result = absl::StrFormat("%d", i16); + + int64_t i64 = provider.ConsumeIntegral(); + result = absl::StrFormat("%d", i64); + + uint64_t u64 = provider.ConsumeIntegral(); + result = absl::StrFormat("%u", u64); + + // Test integer format flags + result = absl::StrFormat("%+d", value); + result = absl::StrFormat("% d", value); + result = absl::StrFormat("%-8d", value); + result = absl::StrFormat("%08d", value); + result = absl::StrFormat("%#x", value); + // Additional flag combinations (were missing) + result = absl::StrFormat("%+#x", value); + result = absl::StrFormat("% #x", value); + result = absl::StrFormat("%-#x", value); + + // Test floating point formats + double double_val = provider.ConsumeFloatingPoint(); + result = absl::StrFormat("%f", double_val); + result = absl::StrFormat("%e", double_val); + result = absl::StrFormat("%g", double_val); + result = absl::StrFormat("%E", double_val); + result = absl::StrFormat("%G", double_val); + result = absl::StrFormat("%.2f", double_val); + result = absl::StrFormat("%10.2f", double_val); + + // Additional float tests (were missing) + result = absl::StrFormat("%a", double_val); + result = absl::StrFormat("%A", double_val); + result = absl::StrFormat("%#f", double_val); + + // Test extreme width/precision (were missing) + result = absl::StrFormat("%100d", value); + result = absl::StrFormat("%.100d", value); + result = absl::StrFormat("%100.100d", value); + + // Test string formats + std::string str = provider.ConsumeRandomLengthString(); + result = absl::StrFormat("%s", str); + result = absl::StrFormat("%10s", str); + result = absl::StrFormat("%-10s", str); + result = absl::StrFormat("%.5s", str); + + // Test invalid format combinations (were missing) + result = absl::StrFormat("%+s", str); // + with string + result = absl::StrFormat("% p", &str); // space with pointer + + // Test pointer format + void* ptr = reinterpret_cast(provider.ConsumeIntegral()); + result = absl::StrFormat("%p", ptr); + + // Test character format + char c = provider.ConsumeIntegral(); + result = absl::StrFormat("%c", c); + + // Test width and precision + int width = provider.ConsumeIntegralInRange(0, 100); + int precision = provider.ConsumeIntegralInRange(0, 20); + result = absl::StrFormat("%*d", width, value); + result = absl::StrFormat("%.*f", precision, double_val); + result = absl::StrFormat("%*.*f", width, precision, double_val); + + // Test limit values + result = absl::StrFormat("%d", std::numeric_limits::max()); + result = absl::StrFormat("%d", std::numeric_limits::min()); + result = absl::StrFormat("%u", std::numeric_limits::max()); + result = absl::StrFormat("%lld", std::numeric_limits::max()); + result = absl::StrFormat("%lld", std::numeric_limits::min()); + result = absl::StrFormat("%llu", std::numeric_limits::max()); + + // Test special floating point values (were missing) + double special_values[] = { + std::numeric_limits::infinity(), + -std::numeric_limits::infinity(), + std::numeric_limits::quiet_NaN(), + std::numeric_limits::denorm_min(), + std::numeric_limits::min(), + std::numeric_limits::max() + }; + + for (double d : special_values) { + result = absl::StrFormat("%f", d); + result = absl::StrFormat("%e", d); + result = absl::StrFormat("%g", d); + result = absl::StrFormat("%a", d); + } + + // Test multiple argument formats + result = absl::StrFormat("%d:%s:%g", value, str, double_val); + result = absl::StrFormat("%x:%p:%.2f", value, ptr, double_val); + result = absl::StrFormat("i=%d s='%s' f=%g", value, str, double_val); + + return 0; +} diff --git a/projects/abseil-cpp/format_parser_fuzzer.cc b/projects/abseil-cpp/format_parser_fuzzer.cc new file mode 100644 index 000000000000..512b9293f96a --- /dev/null +++ b/projects/abseil-cpp/format_parser_fuzzer.cc @@ -0,0 +1,66 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include "absl/strings/str_format.h" +#include "absl/strings/string_view.h" + +// Test specific format strings that are compile-time constants +void TestFormat(int int_val, double double_val, const char* str_val, void* ptr_val) { + std::string result; + + // Test integer formats + result = absl::StrFormat("%d", int_val); + result = absl::StrFormat("%x", int_val); + result = absl::StrFormat("%04d", int_val); + result = absl::StrFormat("%-5d", int_val); + + // Test float formats + result = absl::StrFormat("%f", double_val); + result = absl::StrFormat("%.2f", double_val); + result = absl::StrFormat("%10.4f", double_val); + result = absl::StrFormat("%e", double_val); + + // Test string formats + result = absl::StrFormat("%s", str_val); + result = absl::StrFormat("%10s", str_val); + result = absl::StrFormat("%-10s", str_val); + + // Test pointer format + result = absl::StrFormat("%p", ptr_val); + + // Test combined formats + result = absl::StrFormat("int=%d str=%s float=%.2f ptr=%p", + int_val, str_val, double_val, ptr_val); +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + if (size < 4) return 0; + + FuzzedDataProvider provider(data, size); + + // Generate test values + int int_val = provider.ConsumeIntegral(); + double double_val = provider.ConsumeFloatingPoint(); + std::string str_val = provider.ConsumeRandomLengthString(); + void* ptr_val = reinterpret_cast(provider.ConsumeIntegral()); + + TestFormat(int_val, double_val, str_val.c_str(), ptr_val); + + return 0; +} diff --git a/projects/abseil-cpp/format_summarize_fuzzer.cc b/projects/abseil-cpp/format_summarize_fuzzer.cc new file mode 100644 index 000000000000..31abc22acf7e --- /dev/null +++ b/projects/abseil-cpp/format_summarize_fuzzer.cc @@ -0,0 +1,67 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include "absl/strings/str_format.h" +#include "absl/strings/internal/str_format/arg.h" +#include "absl/strings/internal/str_format/bind.h" + +using absl::str_format_internal::FormatArgImpl; +using absl::str_format_internal::UntypedFormatSpecImpl; + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + if (size < 4) return 0; + + FuzzedDataProvider provider(data, size); + + // Create a fixed-size array of test values + std::vector values; + values.resize(5); + for (int i = 0; i < 5; i++) { + values[i] = provider.ConsumeIntegral(); + } + + // Create FormatArgImpl array from test values + std::vector args; + for (const int& val : values) { + args.push_back(FormatArgImpl(val)); + } + + // Test format strings that match the test patterns from FormatBindTest + const char* format_strings[] = { + "a%4db%dc", // Basic width + "a%.4db%dc", // Basic precision + "a%4.5db%dc", // Width and precision + "a%db%4.5dc", // Mixed formats + "a%db%*.*dc", // Dynamic width/precision + "a%.*fb", // Float precision + "a%1$db%2$*3$.*4$dc", // Positional parameters + "a%4$db%3$*2$.*1$dc", // Reverse positional + "a%04ldb", // Zero padding + "a%-#04lldb", // All flags + "a%1$*5$db", // Positional width + "a%1$.*5$db" // Positional precision + }; + + // Pick a format string and summarize + std::string fmt = provider.PickValueInArray(format_strings); + UntypedFormatSpecImpl format(fmt); + std::string result = absl::str_format_internal::Summarize( + format, absl::MakeSpan(args)); + + return 0; +} diff --git a/projects/abseil-cpp/format_wchar_fuzzer.cc b/projects/abseil-cpp/format_wchar_fuzzer.cc new file mode 100644 index 000000000000..1d555e7cdd2a --- /dev/null +++ b/projects/abseil-cpp/format_wchar_fuzzer.cc @@ -0,0 +1,42 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include + +#include "absl/strings/string_view.h" +#include "absl/strings/internal/str_format/arg.h" +#include "absl/strings/internal/str_format/extension.h" + +using absl::str_format_internal::FormatConversionCharInternal; +using absl::str_format_internal::FormatConversionSpecImpl; +using absl::str_format_internal::FormatSinkImpl; + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + if (size < 4) return 0; + + FuzzedDataProvider provider(data, size); + wchar_t test_value = provider.ConsumeIntegral(); + + std::string out; + FormatSinkImpl sink(&out); + + FormatConversionSpecImpl conv; + conv.set_conversion_char(FormatConversionCharInternal::c); + + absl::str_format_internal::FormatConvertImpl(test_value, conv, &sink); + + return 0; +} diff --git a/projects/abseil-cpp/int128_ostream_fuzzer.cc b/projects/abseil-cpp/int128_ostream_fuzzer.cc new file mode 100644 index 000000000000..53621c9f3c6e --- /dev/null +++ b/projects/abseil-cpp/int128_ostream_fuzzer.cc @@ -0,0 +1,68 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include +#include +#include + +#include "absl/numeric/int128.h" + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + static const std::ios_base::fmtflags kFormatFlags[] = { + std::ios_base::dec, + std::ios_base::hex, + std::ios_base::oct, + std::ios_base::dec | std::ios_base::showbase, + std::ios_base::hex | std::ios_base::showbase, + std::ios_base::oct | std::ios_base::showbase, + std::ios_base::dec | std::ios_base::showpos, + std::ios_base::hex | std::ios_base::uppercase, + std::ios_base::dec | std::ios_base::left, + std::ios_base::dec | std::ios_base::right, + std::ios_base::dec | std::ios_base::internal + }; + + FuzzedDataProvider provider(data, size); + + // Create int128 value + int64_t high = provider.ConsumeIntegral(); + uint64_t low = provider.ConsumeIntegral(); + absl::int128 value = absl::MakeInt128(high, low); + + // Test stream configurations + for (const auto& flag : kFormatFlags) { + std::ostringstream oss; + oss.flags(flag); + + // Add width and fill character + char fill = provider.ConsumeIntegral(); + int width = provider.ConsumeIntegralInRange(0, 50); + oss.fill(fill); + oss.width(width); + + // Stream the value + oss << value; + + // Stream again to verify consistency + std::ostringstream oss2; + oss2.flags(oss.flags()); + oss2.fill(oss.fill()); + oss2.width(oss.width()); + oss2 << value; + } + + return 0; +} diff --git a/projects/abseil-cpp/invoke_object_fuzzer.cc b/projects/abseil-cpp/invoke_object_fuzzer.cc new file mode 100644 index 000000000000..2cad8bda87f9 --- /dev/null +++ b/projects/abseil-cpp/invoke_object_fuzzer.cc @@ -0,0 +1,78 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include +#include +#include "absl/functional/function_ref.h" +#include "absl/functional/internal/function_ref.h" + +struct CallableInt { + int value; + int operator()() const { return value; } +}; + +struct CallableWithArgs { + int operator()(int x, int y) const { return x + y; } +}; + +struct CallableWithMoveOnly { + std::unique_ptr operator()(std::unique_ptr p) const { + return p; + } +}; + +struct CallableVoid { + void operator()(int& x) const { x++; } +}; + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + FuzzedDataProvider provider(data, size); + absl::functional_internal::VoidPtr ptr; + + // Test callable with value + int value = provider.ConsumeIntegral(); + CallableInt ci{value}; + ptr.obj = &ci; + absl::functional_internal::InvokeObject(ptr); + + // Test callable with args + CallableWithArgs cwa; + ptr.obj = &cwa; + absl::functional_internal::InvokeObject( + ptr, + provider.ConsumeIntegral(), + provider.ConsumeIntegral() + ); + + // Test with move-only type + CallableWithMoveOnly cmo; + ptr.obj = &cmo; + absl::functional_internal::InvokeObject< + CallableWithMoveOnly, + std::unique_ptr, + std::unique_ptr>( + ptr, + std::make_unique(provider.ConsumeIntegral()) + ); + + // Test void return + CallableVoid cv; + ptr.obj = &cv; + int ref_value = provider.ConsumeIntegral(); + absl::functional_internal::InvokeObject(ptr, ref_value); + + return 0; +} diff --git a/projects/abseil-cpp/parsed_format_base_fuzzer.cc b/projects/abseil-cpp/parsed_format_base_fuzzer.cc new file mode 100644 index 000000000000..7552d618e90c --- /dev/null +++ b/projects/abseil-cpp/parsed_format_base_fuzzer.cc @@ -0,0 +1,70 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include + +#include "absl/strings/string_view.h" +#include "absl/strings/internal/str_format/arg.h" +#include "absl/strings/internal/str_format/extension.h" + +using absl::str_format_internal::FormatConversionCharInternal; +using absl::str_format_internal::FormatConversionSpecImpl; +using absl::str_format_internal::FormatSinkImpl; + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + static const char kFormatModifiers[] = {'+', '-', ' ', '#', '0'}; + static const char kFormatChars[] = {'d', 'i', 's', 'x', 'X', 'f', 'F', 'g', 'G', 'e', 'E', 'p', 'c'}; + static const char* kLengthMods[] = {"h", "hh", "l", "ll", "L", "z", "j", "t"}; + + FuzzedDataProvider provider(data, size); + + std::string format; + while (provider.remaining_bytes() > 0) { + // Format specifier generation + format += '%'; + + // Positional args (1-9)$ + format += std::to_string(provider.ConsumeIntegralInRange(1, 9)); + format += "$"; + + // Random format flags + format += provider.PickValueInArray(kFormatModifiers); + + // Width - either number or * + format += provider.ConsumeBool() ? "*" : + std::to_string(provider.ConsumeIntegralInRange(1, 100)); + + // Precision - .number or .* + format += "."; + format += provider.ConsumeBool() ? "*" : + std::to_string(provider.ConsumeIntegralInRange(0, 20)); + + // Length modifier + format += provider.PickValueInArray(kLengthMods); + + // Final conversion char + format += provider.PickValueInArray(kFormatChars); + } + + // Test format parsing + absl::string_view format_view(format); + FormatConversionSpecImpl spec; + spec.set_conversion_char(FormatConversionCharInternal::c); + std::string out; + FormatSinkImpl sink(&out); + + return 0; +} diff --git a/projects/abseil-cpp/safe_strto128_fuzzer.cc b/projects/abseil-cpp/safe_strto128_fuzzer.cc new file mode 100644 index 000000000000..ee402abf4898 --- /dev/null +++ b/projects/abseil-cpp/safe_strto128_fuzzer.cc @@ -0,0 +1,36 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include + +#include "absl/strings/string_view.h" +#include "absl/strings/numbers.h" +#include "absl/numeric/int128.h" + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + if (size == 0) return 0; + + FuzzedDataProvider provider(data, size); + absl::int128 signed_value; + absl::uint128 unsigned_value; + + // Test with generated input + std::string test_input = provider.ConsumeRemainingBytesAsString(); + absl::numbers_internal::safe_strto128_base(test_input.c_str(), &signed_value, 10); + absl::numbers_internal::safe_strtou128_base(test_input.c_str(), &unsigned_value, 10); + + return 0; +} diff --git a/projects/abseil-cpp/strcontains_ignorecase_fuzzer.cc b/projects/abseil-cpp/strcontains_ignorecase_fuzzer.cc new file mode 100644 index 000000000000..c4415c3b5284 --- /dev/null +++ b/projects/abseil-cpp/strcontains_ignorecase_fuzzer.cc @@ -0,0 +1,42 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include +#include + +#include "absl/strings/string_view.h" +#include "absl/strings/match.h" +#include "absl/strings/ascii.h" + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + if (size < 2) return 0; // Need at least 2 bytes + + FuzzedDataProvider provider(data, size); + + // Get a random string for the haystack + std::string haystack = provider.ConsumeRandomLengthString(); + + // Get a single char to search for + char needle = provider.ConsumeIntegral(); + + // Create string_view from the haystack string + absl::string_view haystack_view(haystack); + + // Call the function under test + absl::StrContainsIgnoreCase(haystack_view, needle); + + return 0; +}