From 67f8f70db85784654227d4401fe5dcc8c993622a Mon Sep 17 00:00:00 2001 From: Sergey Bronnikov <sergeyb@tarantool.org> Date: Sat, 26 Feb 2022 12:19:18 +0300 Subject: [PATCH] test/fuzz: add fuzzing test for decoding decimals NO_DOC=testing NO_CHANGELOG=testing (cherry picked from commit 4deadeb84e2b3011018eadbbfe2d1e798d95fe5f) --- test/fuzz/CMakeLists.txt | 7 +++++++ test/fuzz/decimal_to_int64_fuzzer.c | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 test/fuzz/decimal_to_int64_fuzzer.c diff --git a/test/fuzz/CMakeLists.txt b/test/fuzz/CMakeLists.txt index 6ad7a203be..f79f2f2907 100644 --- a/test/fuzz/CMakeLists.txt +++ b/test/fuzz/CMakeLists.txt @@ -133,6 +133,13 @@ if (NOT ENABLE_UB_SANITIZER) LIBRARIES xrow fuzzer_config) endif () +# Blocked by https://github.com/tarantool/tarantool/issues/8948. +if (NOT ENABLE_UB_SANITIZER) + create_fuzz_test(PREFIX decimal_to_int64 + SOURCES decimal_to_int64_fuzzer.c + LIBRARIES core fuzzer_config) +endif () + include(ProtobufMutator) # UndefinedBehaviorSanitizer is not supported in LuaJIT. diff --git a/test/fuzz/decimal_to_int64_fuzzer.c b/test/fuzz/decimal_to_int64_fuzzer.c new file mode 100644 index 0000000000..de24dbf48e --- /dev/null +++ b/test/fuzz/decimal_to_int64_fuzzer.c @@ -0,0 +1,19 @@ +#include <string.h> +#include <stdlib.h> +#include "decimal.h" +#include "trivia/util.h" + +int +LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + char *buf = xcalloc(size + 1, sizeof(char)); + if (!buf) + return 0; + memcpy(buf, data, size); + buf[size] = '\0'; + decimal_t d; + decimal_from_string(&d, buf); + free(buf); + + return 0; +} -- GitLab