From 7a155ce913f42baf480b6cf9477f8185aadbcbf2 Mon Sep 17 00:00:00 2001 From: James Zern Date: Wed, 8 Oct 2025 18:57:03 -0700 Subject: [PATCH 1/2] .clang-format: add DerivePointerAlignment: false This will become the default in later versions of clang-format with --style=Google. This will normalize the pointer alignment in the fuzzers. Change-Id: I118aac9758ab2a1af82a907ee61f4a7af88209b1 --- .clang-format | 1 + 1 file changed, 1 insertion(+) diff --git a/.clang-format b/.clang-format index 0e6bbdf3..394685d3 100644 --- a/.clang-format +++ b/.clang-format @@ -1,3 +1,4 @@ --- Language: Cpp BasedOnStyle: Google +DerivePointerAlignment: false From bbbf29a9b6f0f383df35b6bc9380989b87806f6b Mon Sep 17 00:00:00 2001 From: clang-format Date: Wed, 8 Oct 2025 19:02:55 -0700 Subject: [PATCH 2/2] tests/fuzzer: apply clang-format Change-Id: I32b33cb911fe828b0c3f777e4e35fcd7b65068fb --- tests/fuzzer/dec_fuzzer.cc | 4 +-- tests/fuzzer/imageio_fuzzer.cc | 6 ++-- tests/fuzzer/nalloc.h | 62 ++++++++++++++++---------------- tests/fuzzer/webp_info_fuzzer.cc | 4 +-- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/tests/fuzzer/dec_fuzzer.cc b/tests/fuzzer/dec_fuzzer.cc index 3bbed234..5695374f 100644 --- a/tests/fuzzer/dec_fuzzer.cc +++ b/tests/fuzzer/dec_fuzzer.cc @@ -32,10 +32,10 @@ void DecodeWebP(std::string_view arbitrary_bytes) { std::abort(); } nalloc_init(nullptr); - nalloc_start(reinterpret_cast(arbitrary_bytes.data()), + nalloc_start(reinterpret_cast(arbitrary_bytes.data()), arbitrary_bytes.size()); const VP8StatusCode status = - WebPDecode(reinterpret_cast(arbitrary_bytes.data()), + WebPDecode(reinterpret_cast(arbitrary_bytes.data()), arbitrary_bytes.size(), &decoder_config); WebPFreeDecBuffer(&decoder_config.output); // The decoding may fail (because the fuzzed input can be anything) but not diff --git a/tests/fuzzer/imageio_fuzzer.cc b/tests/fuzzer/imageio_fuzzer.cc index 19fa69dc..4bfd1149 100644 --- a/tests/fuzzer/imageio_fuzzer.cc +++ b/tests/fuzzer/imageio_fuzzer.cc @@ -30,7 +30,7 @@ namespace { -void TestReader(const uint8_t *data, size_t size, WebPImageReader reader, +void TestReader(const uint8_t* data, size_t size, WebPImageReader reader, bool keep_alpha, bool use_argb) { WebPPicture pic; if (!WebPPictureInit(&pic)) { @@ -55,8 +55,8 @@ constexpr WebPInputFileFormat kUnknown = WEBP_UNSUPPORTED_FORMAT; void Decode(std::string_view arbitrary_bytes, WebPInputFileFormat format, bool keep_alpha, bool use_argb) { - const uint8_t *data = - reinterpret_cast(arbitrary_bytes.data()); + const uint8_t* data = + reinterpret_cast(arbitrary_bytes.data()); const size_t size = arbitrary_bytes.size(); if (format == kUnknown) { (void)WebPGuessImageType(data, size); // shouldn't fail diff --git a/tests/fuzzer/nalloc.h b/tests/fuzzer/nalloc.h index 3bb744f5..1c8a4697 100644 --- a/tests/fuzzer/nalloc.h +++ b/tests/fuzzer/nalloc.h @@ -106,12 +106,12 @@ extern void __sanitizer_print_stack_trace(void); #endif // Generic init, using env variables to get parameters -void nalloc_init(const char *prog) { +void nalloc_init(const char* prog) { if (nalloc_initialized) { return; } nalloc_initialized = true; - char *bitmask = getenv("NALLOC_FREQ"); + char* bitmask = getenv("NALLOC_FREQ"); if (bitmask) { int shift = atoi(bitmask); if (shift > 0 && shift < 31) { @@ -127,12 +127,12 @@ void nalloc_init(const char *prog) { return; } - char *magic = getenv("NALLOC_MAGIC"); + char* magic = getenv("NALLOC_MAGIC"); if (magic) { nalloc_magic = (uint32_t)strtol(magic, NULL, 0); } - char *verbose = getenv("NALLOC_VERBOSE"); + char* verbose = getenv("NALLOC_VERBOSE"); if (verbose) { nalloc_verbose = true; } @@ -146,7 +146,7 @@ static inline void nalloc_random_update(uint8_t b) { } // Start the failure injections, using a buffer as seed -static int nalloc_start(const uint8_t *data, size_t size) { +static int nalloc_start(const uint8_t* data, size_t size) { if (nalloc_random_bitmask) { if (nalloc_random_state & 0x10) { nalloc_bitmask = 0xFFFFFFFF; @@ -172,7 +172,7 @@ static int nalloc_start(const uint8_t *data, size_t size) { // Stop the failure injections static void nalloc_end() { __sync_fetch_and_sub(&nalloc_running, 1); } -static bool nalloc_backtrace_exclude(size_t size, const char *op) { +static bool nalloc_backtrace_exclude(size_t size, const char* op) { if (nalloc_verbose) { fprintf(stderr, "failed %s(%zu) \n", op, size); #ifdef NALLOC_ASAN @@ -184,7 +184,7 @@ static bool nalloc_backtrace_exclude(size_t size, const char *op) { } // -static bool nalloc_fail(size_t size, const char *op) { +static bool nalloc_fail(size_t size, const char* op) { // do not fail before thread init if (nalloc_runs == 0) { return false; @@ -217,15 +217,15 @@ static bool nalloc_fail(size_t size, const char *op) { // ASAN interceptor for libc routines #ifdef NALLOC_ASAN -extern void *__interceptor_malloc(size_t); -extern void *__interceptor_calloc(size_t, size_t); -extern void *__interceptor_realloc(void *, size_t); -extern void *__interceptor_reallocarray(void *, size_t, size_t); +extern void* __interceptor_malloc(size_t); +extern void* __interceptor_calloc(size_t, size_t); +extern void* __interceptor_realloc(void*, size_t); +extern void* __interceptor_reallocarray(void*, size_t, size_t); -extern ssize_t __interceptor_read(int, void *, size_t); -extern ssize_t __interceptor_write(int, const void *, size_t); -extern ssize_t __interceptor_recv(int, void *, size_t, int); -extern ssize_t __interceptor_send(int, const void *, size_t, int); +extern ssize_t __interceptor_read(int, void*, size_t); +extern ssize_t __interceptor_write(int, const void*, size_t); +extern ssize_t __interceptor_recv(int, void*, size_t, int); +extern ssize_t __interceptor_send(int, const void*, size_t, int); #define nalloc_malloc(s) __interceptor_malloc(s) #define nalloc_calloc(s, n) __interceptor_calloc(s, n) @@ -238,15 +238,15 @@ extern ssize_t __interceptor_send(int, const void *, size_t, int); #define nalloc_send(f, b, s, x) __interceptor_send(f, b, s, x) #else -extern void *__libc_malloc(size_t); -extern void *__libc_calloc(size_t, size_t); -extern void *__libc_realloc(void *, size_t); -extern void *__libc_reallocarray(void *, size_t, size_t); +extern void* __libc_malloc(size_t); +extern void* __libc_calloc(size_t, size_t); +extern void* __libc_realloc(void*, size_t); +extern void* __libc_reallocarray(void*, size_t, size_t); -extern ssize_t __read(int, void *, size_t); -extern ssize_t __write(int, const void *, size_t); -extern ssize_t __recv(int, void *, size_t, int); -extern ssize_t __send(int, const void *, size_t, int); +extern ssize_t __read(int, void*, size_t); +extern ssize_t __write(int, const void*, size_t); +extern ssize_t __recv(int, void*, size_t, int); +extern ssize_t __send(int, const void*, size_t, int); #define nalloc_malloc(s) __libc_malloc(s) #define nalloc_calloc(s, n) __libc_calloc(s, n) @@ -260,7 +260,7 @@ extern ssize_t __send(int, const void *, size_t, int); #endif // nalloc standard function overwrites with pseudo-random failures -ssize_t read(int fd, void *buf, size_t count) { +ssize_t read(int fd, void* buf, size_t count) { if (nalloc_fail(count, "read")) { errno = EIO; return -1; @@ -268,7 +268,7 @@ ssize_t read(int fd, void *buf, size_t count) { return nalloc_read(fd, buf, count); } -ssize_t write(int fd, const void *buf, size_t count) { +ssize_t write(int fd, const void* buf, size_t count) { if (nalloc_fail(count, "write")) { errno = EIO; return -1; @@ -276,7 +276,7 @@ ssize_t write(int fd, const void *buf, size_t count) { return nalloc_write(fd, buf, count); } -ssize_t recv(int fd, void *buf, size_t count, int flags) { +ssize_t recv(int fd, void* buf, size_t count, int flags) { if (nalloc_fail(count, "recv")) { errno = EIO; return -1; @@ -284,7 +284,7 @@ ssize_t recv(int fd, void *buf, size_t count, int flags) { return nalloc_recv(fd, buf, count, flags); } -ssize_t send(int fd, const void *buf, size_t count, int flags) { +ssize_t send(int fd, const void* buf, size_t count, int flags) { if (nalloc_fail(count, "send")) { errno = EIO; return -1; @@ -292,7 +292,7 @@ ssize_t send(int fd, const void *buf, size_t count, int flags) { return nalloc_send(fd, buf, count, flags); } -void *calloc(size_t nmemb, size_t size) { +void* calloc(size_t nmemb, size_t size) { if (nalloc_fail(size, "calloc")) { errno = ENOMEM; return NULL; @@ -300,7 +300,7 @@ void *calloc(size_t nmemb, size_t size) { return nalloc_calloc(nmemb, size); } -void *malloc(size_t size) { +void* malloc(size_t size) { if (nalloc_fail(size, "malloc")) { errno = ENOMEM; return NULL; @@ -308,7 +308,7 @@ void *malloc(size_t size) { return nalloc_malloc(size); } -void *realloc(void *ptr, size_t size) { +void* realloc(void* ptr, size_t size) { if (nalloc_fail(size, "realloc")) { errno = ENOMEM; return NULL; @@ -316,7 +316,7 @@ void *realloc(void *ptr, size_t size) { return nalloc_realloc(ptr, size); } -void *reallocarray(void *ptr, size_t nmemb, size_t size) { +void* reallocarray(void* ptr, size_t nmemb, size_t size) { if (nalloc_fail(size, "reallocarray")) { errno = ENOMEM; return NULL; diff --git a/tests/fuzzer/webp_info_fuzzer.cc b/tests/fuzzer/webp_info_fuzzer.cc index a9f3f259..7ced2fe6 100644 --- a/tests/fuzzer/webp_info_fuzzer.cc +++ b/tests/fuzzer/webp_info_fuzzer.cc @@ -28,14 +28,14 @@ void WebPInfoTest(std::string_view data) { nalloc_init(nullptr); - nalloc_start(reinterpret_cast(data.data()), data.size()); + nalloc_start(reinterpret_cast(data.data()), data.size()); WebPInfo webp_info; WebPInfoInit(&webp_info); webp_info.quiet = 1; webp_info.show_summary = 0; webp_info.show_diagnosis = 0; webp_info.parse_bitstream = 1; - WebPData webp_data = {reinterpret_cast(data.data()), + WebPData webp_data = {reinterpret_cast(data.data()), data.size()}; AnalyzeWebP(&webp_info, &webp_data); nalloc_end();