@@ -49,6 +49,32 @@ IgzipDecompressor_dealloc(IgzipDecompressor *self)
49
49
Py_TYPE (self )-> tp_free ((PyObject * )self );
50
50
}
51
51
52
+
53
+ static int
54
+ set_inflate_zdict_IgzipDecompressor (IgzipDecompressor * self )
55
+ {
56
+ Py_buffer zdict_buf ;
57
+ if (PyObject_GetBuffer (self -> zdict , & zdict_buf , PyBUF_SIMPLE ) == -1 ) {
58
+ return -1 ;
59
+ }
60
+ if ((size_t )zdict_buf .len > UINT32_MAX ) {
61
+ PyErr_SetString (PyExc_OverflowError ,
62
+ "zdict length does not fit in an unsigned 32-bit integer" );
63
+ PyBuffer_Release (& zdict_buf );
64
+ return -1 ;
65
+ }
66
+ int err ;
67
+ err = isal_inflate_set_dict (& self -> state ,
68
+ zdict_buf .buf , (uint32_t )zdict_buf .len );
69
+ PyBuffer_Release (& zdict_buf );
70
+ if (err != ISAL_DECOMP_OK ) {
71
+ isal_inflate_error (err );
72
+ return -1 ;
73
+ }
74
+ return 0 ;
75
+ }
76
+
77
+
52
78
/* Decompress data of length d->bzs_avail_in_real in d->state.next_in. The output
53
79
buffer is allocated dynamically and returned. At most max_length bytes are
54
80
returned, so some of the input may not be consumed. d->state.next_in and
@@ -105,12 +131,28 @@ decompress_buf(IgzipDecompressor *self, Py_ssize_t max_length)
105
131
err = isal_inflate (& (self -> state ));
106
132
Py_END_ALLOW_THREADS ;
107
133
108
- if (err != ISAL_DECOMP_OK ){
109
- isal_inflate_error (err );
110
- goto error ;
134
+ switch (err ) {
135
+ case ISAL_DECOMP_OK :
136
+ break ;
137
+ case ISAL_NEED_DICT :
138
+ if (self -> zdict != NULL ) {
139
+ if (set_inflate_zdict_IgzipDecompressor (self ) < 0 ) {
140
+ goto error ;
141
+ }
142
+ else
143
+ break ;
144
+ }
145
+ else {
146
+ isal_inflate_error (err );
147
+ goto error ;
148
+ }
149
+ default :
150
+ isal_inflate_error (err );
151
+ goto error ;
111
152
}
112
- } while (self -> state .avail_out == 0 &&
113
- self -> state .block_state != ISAL_BLOCK_FINISH );
153
+
154
+ } while (self -> state .avail_out == 0 || err == ISAL_NEED_DICT );
155
+
114
156
} while (self -> avail_in_real != 0 &&
115
157
self -> state .block_state != ISAL_BLOCK_FINISH );
116
158
@@ -414,7 +456,6 @@ igzip_lib_IgzipDecompressor__new__(PyTypeObject *type,
414
456
return NULL ;
415
457
}
416
458
IgzipDecompressor * self = PyObject_New (IgzipDecompressor , type );
417
- int err ;
418
459
self -> eof = 0 ;
419
460
self -> needs_input = 1 ;
420
461
self -> avail_in_real = 0 ;
@@ -436,26 +477,10 @@ igzip_lib_IgzipDecompressor__new__(PyTypeObject *type,
436
477
self -> state .hist_bits = hist_bits ;
437
478
self -> state .crc_flag = flag ;
438
479
if (self -> zdict != NULL ){
439
- Py_buffer zdict_buf ;
440
- if (PyObject_GetBuffer (self -> zdict , & zdict_buf , PyBUF_SIMPLE ) == -1 ) {
441
- Py_CLEAR (self );
442
- return NULL ;
443
- }
444
- if ((size_t )zdict_buf .len > UINT32_MAX ) {
445
- PyErr_SetString (PyExc_OverflowError ,
446
- "zdict length does not fit in an unsigned 32-bits int" );
447
- PyBuffer_Release (& zdict_buf );
480
+ if (set_inflate_zdict_IgzipDecompressor (self ) < 0 ) {
448
481
Py_CLEAR (self );
449
482
return NULL ;
450
483
}
451
- err = isal_inflate_set_dict (& (self -> state ), zdict_buf .buf ,
452
- (uint32_t )zdict_buf .len );
453
- PyBuffer_Release (& zdict_buf );
454
- if (err != ISAL_DECOMP_OK ) {
455
- isal_inflate_error (err );
456
- Py_CLEAR (self );
457
- return NULL ;
458
- }
459
484
}
460
485
return (PyObject * )self ;
461
486
}
0 commit comments