]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fix potential NULL pointer dereference in ZSTD_customCalloc when custom allocator... 4613/head
authorNiDU-NINJA <alnida1505@gmail.com>
Sat, 7 Mar 2026 08:27:15 +0000 (08:27 +0000)
committerNiDU-NINJA <alnida1505@gmail.com>
Sat, 7 Mar 2026 08:27:15 +0000 (08:27 +0000)
lib/common/allocations.h

index 5e8995501090fd631c0773e2c5ec233e7acc05e6..d4d392998f7870a40c76c2b2850073857b3b7af5 100644 (file)
@@ -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;
     }