diff --git a/c-ext/decompressor.c b/c-ext/decompressor.c index 97e63742..8defed14 100644 --- a/c-ext/decompressor.c +++ b/c-ext/decompressor.c @@ -1684,6 +1684,11 @@ Decompressor_multi_decompress_to_buffer(ZstdDecompressor *self, PyObject *args, goto finally; } + if (0 == frameCount) { + PyErr_SetString(PyExc_ValueError, "no source elements found"); + goto finally; + } + /* We now have an array with info about our inputs and outputs. Feed it into our generic decompression function. */ frameSources.frames = framePointers; diff --git a/tests/test_decompressor_multi_decompress_to_buffer.py b/tests/test_decompressor_multi_decompress_to_buffer.py index eed85fe2..df25ff7c 100644 --- a/tests/test_decompressor_multi_decompress_to_buffer.py +++ b/tests/test_decompressor_multi_decompress_to_buffer.py @@ -33,6 +33,21 @@ def test_invalid_inputs(self): ): dctx.multi_decompress_to_buffer([b"foobarbaz"]) + def test_empty_input(self): + dctx = zstd.ZstdDecompressor() + frames = [[], zstd.BufferWithSegments(b"", b"")] + + for frame in frames: + for threads in (0, 2, -1): + for kwargs in ({}, {"decompressed_sizes": b""}): + with self.subTest( + frames=frame, threads=threads, kwargs=kwargs + ): + with self.assertRaises(ValueError): + dctx.multi_decompress_to_buffer( + frame, threads=threads, **kwargs + ) + def test_list_input(self): cctx = zstd.ZstdCompressor()