|
22 | 22 | Library to speed up its methods."""
|
23 | 23 |
|
24 | 24 | import argparse
|
25 |
| -import functools |
26 | 25 | import gzip
|
27 | 26 | import io
|
28 | 27 | import os
|
29 |
| -import _compression |
30 | 28 | import sys
|
31 | 29 | from gzip import READ, WRITE
|
| 30 | + |
| 31 | +import _compression |
| 32 | + |
32 | 33 | from . import isal_zlib
|
33 | 34 |
|
34 | 35 | __all__ = ["IGzipFile", "open", "compress", "decompress", "BadGzipFile"]
|
@@ -146,27 +147,20 @@ def write(self, data):
|
146 | 147 | return length
|
147 | 148 |
|
148 | 149 |
|
149 |
| -# The gzip._GzipReader does all sorts of complex stuff. While using the |
150 |
| -# standard DecompressReader by _compression relies more on the C implementation |
151 |
| -# side of things. It is much simpler. Gzip header interpretation and gzip |
152 |
| -# checksum checking is already implemented in the isa-l library. So no need |
153 |
| -# to do so in pure python. |
154 | 150 | class _IGzipReader(gzip._GzipReader):
|
155 | 151 | def __init__(self, fp):
|
156 | 152 | super().__init__(fp)
|
157 | 153 | self._decomp_factory = isal_zlib.decompressobj
|
158 | 154 | self._decomp_args = dict(wbits=64+isal_zlib.MAX_WBITS)
|
| 155 | + # Set wbits such that ISAL_GZIP_NO_HDR_VER is used. This means that |
| 156 | + # it does not read a header, and it verifies the trailer. |
159 | 157 | self._decompressor = self._decomp_factory(**self._decomp_args)
|
160 | 158 |
|
161 | 159 | def _add_read_data(self, data):
|
162 |
| - self._crc = isal_zlib.crc32(data, self._crc) |
| 160 | + # isa-l verifies the trailer data, so no need to keep track of the crc. |
163 | 161 | self._stream_size = self._stream_size + len(data)
|
164 | 162 |
|
165 | 163 | def _read_eof(self):
|
166 |
| - crc32 = self._decompressor.crc |
167 |
| - if crc32 != self._crc: |
168 |
| - raise BadGzipFile( |
169 |
| - f"CRC check failed {hex(crc32)} != {hex(self._crc)}") |
170 | 164 | # Gzip files can be padded with zeroes and still have archives.
|
171 | 165 | # Consume all zero bytes and set the file position to the first
|
172 | 166 | # non-zero byte. See http://www.gzip.org/#faq8
|
|
0 commit comments