summaryrefslogtreecommitdiff
path: root/archived/projt-launcher/fuzz/fuzz_nbt_reader.cpp
diff options
context:
space:
mode:
authorMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 18:51:45 +0300
committerMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 18:51:45 +0300
commitd3261e64152397db2dca4d691a990c6bc2a6f4dd (patch)
treefac2f7be638651181a72453d714f0f96675c2b8b /archived/projt-launcher/fuzz/fuzz_nbt_reader.cpp
parent31b9a8949ed0a288143e23bf739f2eb64fdc63be (diff)
downloadProject-Tick-d3261e64152397db2dca4d691a990c6bc2a6f4dd.tar.gz
Project-Tick-d3261e64152397db2dca4d691a990c6bc2a6f4dd.zip
NOISSUE add archived projects
Signed-off-by: Mehmet Samet Duman <yongdohyun@projecttick.org>
Diffstat (limited to 'archived/projt-launcher/fuzz/fuzz_nbt_reader.cpp')
-rw-r--r--archived/projt-launcher/fuzz/fuzz_nbt_reader.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/archived/projt-launcher/fuzz/fuzz_nbt_reader.cpp b/archived/projt-launcher/fuzz/fuzz_nbt_reader.cpp
new file mode 100644
index 0000000000..d6b1291c6f
--- /dev/null
+++ b/archived/projt-launcher/fuzz/fuzz_nbt_reader.cpp
@@ -0,0 +1,36 @@
+#include <cstdint>
+#include <exception>
+#include <sstream>
+#include <string>
+
+#include "io/stream_reader.h"
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ // Avoid excessive allocations on pathological inputs
+ // Very strict limit to prevent array allocation bombs
+ // E.g., NBT array with count 0x92929292 would allocate 3.2GB
+ constexpr size_t kMaxInputSize = 4 * 1024; // 4 KiB (was 64 KiB)
+ if (!data || size == 0 || size > kMaxInputSize)
+ {
+ return 0;
+ }
+
+ try
+ {
+ // Use custom string stream without extra copies
+ std::istringstream stream(std::string(reinterpret_cast<const char*>(data), size), std::ios::binary);
+ nbt::io::read_compound(stream);
+ }
+ catch (const std::exception&)
+ {
+ // Expected for malformed inputs or resource exhaustion
+ }
+ catch (const std::bad_alloc&)
+ {
+ // Handle out-of-memory gracefully
+ return -1;
+ }
+
+ return 0;
+}