From 3f8f9b3f89244638f10bca664c120fd28cb14efe Mon Sep 17 00:00:00 2001 From: NiDU-NINJA Date: Sat, 7 Mar 2026 08:27:15 +0000 Subject: [PATCH] Fix potential NULL pointer dereference in ZSTD_customCalloc when custom allocator fails --- lib/common/allocations.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/common/allocations.h b/lib/common/allocations.h index 5e8995501..d4d392998 100644 --- a/lib/common/allocations.h +++ b/lib/common/allocations.h @@ -33,9 +33,13 @@ MEM_STATIC void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem) MEM_STATIC void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem) { if (customMem.customAlloc) { - /* calloc implemented as malloc+memset; - * not as efficient as calloc, but next best guess for custom malloc */ + /* calloc implemented as malloc+memset */ void* const ptr = customMem.customAlloc(customMem.opaque, size); + + if (ptr == NULL) { + return NULL; + } + ZSTD_memset(ptr, 0, size); return ptr; } -- 2.47.3