@@ -27,10 +27,16 @@ static PyObject * xdelta3_execute(PyObject *self, PyObject *args)
27
27
output_buf , & output_size , output_alloc , flags );
28
28
} else {
29
29
// 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
+ }
34
40
}
35
41
36
42
if (result == 0 ) {
@@ -40,12 +46,8 @@ static PyObject * xdelta3_execute(PyObject *self, PyObject *args)
40
46
}
41
47
42
48
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" );
49
51
} else {
50
52
char exc_str [80 ];
51
53
sprintf (exc_str , "Error occur executing xdelta3: %s" , xd3_strerror (result ));
0 commit comments