From e95586ead78f785f6511d2f8b8675129607313cb Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Thu, 21 Dec 2017 17:09:04 +0000 Subject: [PATCH] double output_alloc on ENOSPC --- xdelta3/_xdelta3.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/xdelta3/_xdelta3.c b/xdelta3/_xdelta3.c index ceb2e54..e6a4539 100644 --- a/xdelta3/_xdelta3.c +++ b/xdelta3/_xdelta3.c @@ -27,10 +27,14 @@ static PyObject * xdelta3_execute(PyObject *self, PyObject *args) output_buf, &output_size, output_alloc, flags); } else { // output shouldn't be bigger than the original plus the delta, but give a little leeway - output_alloc = input_size + source_size * 2; - output_buf = main_malloc(output_alloc); - result = xd3_decode_memory(input_bytes, input_size, source_bytes, source_size, - output_buf, &output_size, output_alloc, flags); + output_alloc = input_size + source_size; + result = ENOSPC; + while (result == ENOSPC) { + output_buf = main_malloc(output_alloc); + result = xd3_decode_memory(input_bytes, input_size, source_bytes, source_size, + output_buf, &output_size, output_alloc, flags); + output_alloc = output_alloc * 2; + } } if (result == 0) { @@ -40,12 +44,8 @@ static PyObject * xdelta3_execute(PyObject *self, PyObject *args) } if(result == ENOSPC) { - if (action == 0) { - // all is well, just not efficient delta could be found - PyErr_SetString(NoDeltaFound, "No delta found shorter than the input value"); - } else { - PyErr_SetString(XDeltaError, "Output of decoding delta longer than expected"); - } + // all is well, just not efficient delta could be found + PyErr_SetString(NoDeltaFound, "No delta found shorter than the input value"); } else { char exc_str[80]; sprintf(exc_str, "Error occur executing xdelta3: %s", xd3_strerror(result));