From 7a5c9ad586847810e8950c8f542f685606b4bcaf Mon Sep 17 00:00:00 2001 From: Stuart Geipel Date: Wed, 29 Jul 2026 11:51:22 -0400 Subject: [PATCH] Add error checking to zstd hdf5 plugin This PR adds error checking to the zstd hdf5 plugin. Previously it would return uninitialized memory from malloc when any zstd error occurred. --- lib/hdf5_plugins/ZSTD/src/H5Zzstd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/hdf5_plugins/ZSTD/src/H5Zzstd.c b/lib/hdf5_plugins/ZSTD/src/H5Zzstd.c index b96fa84c..4f527042 100644 --- a/lib/hdf5_plugins/ZSTD/src/H5Zzstd.c +++ b/lib/hdf5_plugins/ZSTD/src/H5Zzstd.c @@ -66,10 +66,16 @@ H5Z_filter_zstd(unsigned int flags, size_t cd_nelmts, const unsigned int cd_valu if (flags & H5Z_FLAG_REVERSE) { /* We're decompressing */ size_t decompSize = ZSTD_getFrameContentSize(*buf, origSize); + if (decompSize == 0 || decompSize == ZSTD_CONTENTSIZE_UNKNOWN || + decompSize == ZSTD_CONTENTSIZE_ERROR) + goto error; + if (NULL == (outbuf = malloc(decompSize))) goto error; decompSize = ZSTD_decompress(outbuf, decompSize, inbuf, origSize); + if (ZSTD_isError(decompSize)) + goto error; #ifdef ZSTD_DEBUG fprintf(stderr, " decompressing nbytes: %ld\n", decompSize); @@ -104,6 +110,8 @@ H5Z_filter_zstd(unsigned int flags, size_t cd_nelmts, const unsigned int cd_valu goto error; compSize = ZSTD_compress(outbuf, compSize, inbuf, origSize, aggression); + if (ZSTD_isError(compSize)) + goto error; #ifdef ZSTD_DEBUG fprintf(stderr, " compressing nbytes: %ld\n", compSize);