--- a/contrib/python-zstandard/c-ext/decompressobj.c Tue Sep 25 20:55:03 2018 +0900
+++ b/contrib/python-zstandard/c-ext/decompressobj.c Mon Oct 08 16:27:40 2018 -0700
@@ -33,6 +33,8 @@
PyObject* result = NULL;
Py_ssize_t resultSize = 0;
+ output.dst = NULL;
+
if (self->finished) {
PyErr_SetString(ZstdError, "cannot use a decompressobj multiple times");
return NULL;
@@ -53,6 +55,12 @@
goto finally;
}
+ /* Special case of empty input. Output will always be empty. */
+ if (source.len == 0) {
+ result = PyBytes_FromString("");
+ goto finally;
+ }
+
input.src = source.buf;
input.size = source.len;
input.pos = 0;
@@ -65,8 +73,7 @@
output.size = self->outSize;
output.pos = 0;
- /* Read input until exhausted. */
- while (input.pos < input.size) {
+ while (1) {
Py_BEGIN_ALLOW_THREADS
zresult = ZSTD_decompress_generic(self->decompressor->dctx, &output, &input);
Py_END_ALLOW_THREADS
@@ -98,9 +105,13 @@
goto except;
}
}
+ }
- output.pos = 0;
+ if (zresult == 0 || (input.pos == input.size && output.pos == 0)) {
+ break;
}
+
+ output.pos = 0;
}
if (!result) {