From: NiDU-NINJA Date: Sat, 7 Mar 2026 08:27:15 +0000 (+0000) Subject: Fix potential NULL pointer dereference in ZSTD_customCalloc when custom allocator... X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=refs%2Fpull%2F4613%2Fhead;p=thirdparty%2Fzstd.git Fix potential NULL pointer dereference in ZSTD_customCalloc when custom allocator fails --- 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; }