@@ -409,6 +409,7 @@ cdef class Decompress:
409
409
self .stream.avail_out = 0
410
410
cdef unsigned long prev_avail_out
411
411
cdef unsigned long bytes_written
412
+ cdef Py_ssize_t unused_bytes
412
413
cdef int err
413
414
cdef bint last_round = 0
414
415
# This loop reads all the input bytes. If there are no input bytes
@@ -444,13 +445,15 @@ cdef class Decompress:
444
445
# leftover input data in self->unused_data.
445
446
self .eof = 1
446
447
if self .stream.avail_in > 0 :
447
- self .unused_data = data[total_bytes:]
448
+ unused_bytes = self .stream.avail_in
449
+ self .unused_data = data[- unused_bytes:]
448
450
self .stream.avail_in = 0
449
451
if self .stream.avail_in > 0 or self .unconsumed_tail:
450
452
# This code handles two distinct cases:
451
453
# 1. Output limit was reached. Save leftover input in unconsumed_tail.
452
454
# 2. All input data was consumed. Clear unconsumed_tail.
453
- self .unconsumed_tail = data[total_bytes:]
455
+ unused_bytes = self .stream.avail_in
456
+ self .unconsumed_tail = data[- unused_bytes:]
454
457
return b" " .join(out)
455
458
456
459
def flush (self , Py_ssize_t length = DEF_BUF_SIZE):
@@ -471,6 +474,7 @@ cdef class Decompress:
471
474
out = []
472
475
cdef unsigned long obuflen = length
473
476
cdef unsigned char * obuf = < unsigned char * > PyMem_Malloc(obuflen * sizeof(char ))
477
+ cdef Py_ssize_t unused_bytes
474
478
475
479
try :
476
480
while (self .stream.block_state != ISAL_BLOCK_FINISH
@@ -495,13 +499,14 @@ cdef class Decompress:
495
499
self .eof = 1
496
500
self .is_initialised = 0
497
501
if self .stream.avail_in > 0 :
498
- self .unused_data = data[total_bytes:]
499
- self .stream.avail_in = 0
502
+ unused_bytes = self .stream.avail_in
503
+ self .unused_data = data[ - unused_bytes:]
500
504
if self .stream.avail_in > 0 or self .unconsumed_tail:
501
505
# This code handles two distinct cases:
502
506
# 1. Output limit was reached. Save leftover input in unconsumed_tail.
503
507
# 2. All input data was consumed. Clear unconsumed_tail.
504
- self .unconsumed_tail = data[total_bytes:]
508
+ unused_bytes = self .stream.avail_in
509
+ self .unconsumed_tail = data[- unused_bytes:]
505
510
return b" " .join(out)
506
511
finally :
507
512
PyMem_Free(obuf)
0 commit comments