Skip to content
This repository was archived by the owner on Apr 23, 2022. It is now read-only.

Commit e95586e

Browse files
committed
double output_alloc on ENOSPC
1 parent d1c27a6 commit e95586e

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

xdelta3/_xdelta3.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ static PyObject * xdelta3_execute(PyObject *self, PyObject *args)
2727
output_buf, &output_size, output_alloc, flags);
2828
} else {
2929
// output shouldn't be bigger than the original plus the delta, but give a little leeway
30-
output_alloc = input_size + source_size * 2;
31-
output_buf = main_malloc(output_alloc);
32-
result = xd3_decode_memory(input_bytes, input_size, source_bytes, source_size,
33-
output_buf, &output_size, output_alloc, flags);
30+
output_alloc = input_size + source_size;
31+
result = ENOSPC;
32+
while (result == ENOSPC) {
33+
output_buf = main_malloc(output_alloc);
34+
result = xd3_decode_memory(input_bytes, input_size, source_bytes, source_size,
35+
output_buf, &output_size, output_alloc, flags);
36+
output_alloc = output_alloc * 2;
37+
}
3438
}
3539

3640
if (result == 0) {
@@ -40,12 +44,8 @@ static PyObject * xdelta3_execute(PyObject *self, PyObject *args)
4044
}
4145

4246
if(result == ENOSPC) {
43-
if (action == 0) {
44-
// all is well, just not efficient delta could be found
45-
PyErr_SetString(NoDeltaFound, "No delta found shorter than the input value");
46-
} else {
47-
PyErr_SetString(XDeltaError, "Output of decoding delta longer than expected");
48-
}
47+
// all is well, just not efficient delta could be found
48+
PyErr_SetString(NoDeltaFound, "No delta found shorter than the input value");
4949
} else {
5050
char exc_str[80];
5151
sprintf(exc_str, "Error occur executing xdelta3: %s", xd3_strerror(result));

0 commit comments

Comments
 (0)