You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by sw...@apache.org on 2025/02/05 07:00:40 UTC

(logging-log4cxx) 01/01: Prevent timeout fault running JSONLayoutFuzzer

This is an automated email from the ASF dual-hosted git repository.

swebb2066 pushed a commit to branch prevent_oss_fuzz_timeout
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git

commit d3c20d3e21968085f1a83d8559b7e53a4983679e
Author: Stephen Webb <sw...@gmail.com>
AuthorDate: Wed Feb 5 18:00:10 2025 +1100

    Prevent timeout fault running JSONLayoutFuzzer
---
 src/fuzzers/cpp/JSONLayoutFuzzer.cpp | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/src/fuzzers/cpp/JSONLayoutFuzzer.cpp b/src/fuzzers/cpp/JSONLayoutFuzzer.cpp
index 45529323..e6c1faf3 100644
--- a/src/fuzzers/cpp/JSONLayoutFuzzer.cpp
+++ b/src/fuzzers/cpp/JSONLayoutFuzzer.cpp
@@ -24,6 +24,13 @@
 #include <log4cxx/jsonlayout.h>
 #include <log4cxx/helpers/transcoder.h>
 
+namespace
+{
+	const int MaxKeyLength = 50;
+	const int MaxValueLength = 500;
+	const int MaxMessageLength = 2000;
+}
+
 using namespace log4cxx;
 using namespace log4cxx::helpers;
 using namespace log4cxx::spi;
@@ -48,17 +55,17 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
 	}
 
 	// Create random strings we need later
-	std::string key1Str = fdp.ConsumeRandomLengthString();
-	std::string val1Str = fdp.ConsumeRandomLengthString();
-	std::string key2Str = fdp.ConsumeRandomLengthString();
-	std::string val2Str = fdp.ConsumeRandomLengthString();
-	std::string key3Str = fdp.ConsumeRandomLengthString();
-	std::string val3Str = fdp.ConsumeRandomLengthString();
-	std::string key4Str = fdp.ConsumeRandomLengthString();
-	std::string val4Str = fdp.ConsumeRandomLengthString();
-	std::string ndcMessageStr = fdp.ConsumeRandomLengthString();
-	std::string loggerStr = fdp.ConsumeRandomLengthString();
-	std::string contentStr = fdp.ConsumeRemainingBytesAsString();
+	std::string key1Str = fdp.ConsumeRandomLengthString(MaxKeyLength);
+	std::string val1Str = fdp.ConsumeRandomLengthString(MaxValueLength);
+	std::string key2Str = fdp.ConsumeRandomLengthString(MaxKeyLength);
+	std::string val2Str = fdp.ConsumeRandomLengthString(MaxValueLength);
+	std::string key3Str = fdp.ConsumeRandomLengthString(MaxKeyLength);
+	std::string val3Str = fdp.ConsumeRandomLengthString(MaxValueLength);
+	std::string key4Str = fdp.ConsumeRandomLengthString(MaxKeyLength);
+	std::string val4Str = fdp.ConsumeRandomLengthString(MaxValueLength);
+	std::string ndcMessageStr = fdp.ConsumeRandomLengthString(MaxMessageLength);
+	std::string loggerStr = fdp.ConsumeRandomLengthString(MaxKeyLength);
+	std::string contentStr = fdp.ConsumeRandomLengthString(MaxMessageLength);
 
 	LogString key1, val1, key2, val2, key3, val3, key4, val4, ndcMessage, logger, content;
 	Transcoder::decode(key1Str, key1);