From b683c0dbe278f71e371376847deebd44fdcf392f Mon Sep 17 00:00:00 2001 From: Robert Rose Date: Sun, 24 Nov 2024 23:36:53 +0100 Subject: [PATCH] prevent possible segfault when creating seek table Add a check whether the seek table of a `ZSTD_seekable` is initialized before creating a new seek table from it. Return `NULL`, if the check fails. --- contrib/seekable_format/zstdseek_decompress.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/seekable_format/zstdseek_decompress.c b/contrib/seekable_format/zstdseek_decompress.c index 4fefc5f2eb6..5ee6e0541a5 100644 --- a/contrib/seekable_format/zstdseek_decompress.c +++ b/contrib/seekable_format/zstdseek_decompress.c @@ -252,6 +252,8 @@ size_t ZSTD_seekable_free(ZSTD_seekable* zs) ZSTD_seekTable* ZSTD_seekTable_create_fromSeekable(const ZSTD_seekable* zs) { + assert(zs != NULL); + if (zs->seekTable.entries == NULL) return NULL; ZSTD_seekTable* const st = (ZSTD_seekTable*)malloc(sizeof(ZSTD_seekTable)); if (st==NULL) return NULL;