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

Commit aad1eff

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

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

xdelta3/_xdelta3.c

+12-10
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@ 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+
while (1) {
32+
output_buf = main_malloc(output_alloc);
33+
result = xd3_decode_memory(input_bytes, input_size, source_bytes, source_size,
34+
output_buf, &output_size, output_alloc, flags);
35+
if (result != ENOSPC) {
36+
break;
37+
}
38+
output_alloc = output_alloc * 2;
39+
}
3440
}
3541

3642
if (result == 0) {
@@ -40,12 +46,8 @@ static PyObject * xdelta3_execute(PyObject *self, PyObject *args)
4046
}
4147

4248
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-
}
49+
// all is well, just no efficient delta could be found
50+
PyErr_SetString(NoDeltaFound, "No delta found shorter than the input value");
4951
} else {
5052
char exc_str[80];
5153
sprintf(exc_str, "Error occur executing xdelta3: %s", xd3_strerror(result));

0 commit comments

Comments
 (0)