Fix log.debug statement in lzw.py by ensuring that self.table is always set (#732)
* Fix log.debug statement in lzw.py by ensuring that self.table is always set. * Add CHANGELOG.mdpull/731/head
parent
782368b911
commit
13021c9875
|
@ -8,11 +8,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
|
||||
### Fixed
|
||||
|
||||
- `TypeError` in lzw.py when `self.table` is not set ([#732](https://github.com/pdfminer/pdfminer.six/pull/732))
|
||||
- `TypeError` in encodingdb.py when name of unicode is not
|
||||
str ([#733](https://github.com/pdfminer/pdfminer.six/pull/733))
|
||||
- `TypeError` in HTMLConverter when using a bytes fontname ([#734](https://github.com/pdfminer/pdfminer.six/pull/734))
|
||||
|
||||
|
||||
## [20220319]
|
||||
|
||||
### Added
|
||||
|
|
|
@ -16,7 +16,7 @@ class LZWDecoder:
|
|||
self.bpos = 8
|
||||
self.nbits = 9
|
||||
# NB: self.table stores None only in indices 256 and 257
|
||||
self.table: Optional[List[Optional[bytes]]] = None
|
||||
self.table: List[Optional[bytes]] = []
|
||||
self.prevbuf: Optional[bytes] = None
|
||||
|
||||
def readbits(self, bits: int) -> int:
|
||||
|
@ -55,10 +55,8 @@ class LZWDecoder:
|
|||
elif code == 257:
|
||||
pass
|
||||
elif not self.prevbuf:
|
||||
assert self.table is not None
|
||||
x = self.prevbuf = cast(bytes, self.table[code]) # assume not None
|
||||
else:
|
||||
assert self.table is not None
|
||||
if code < len(self.table):
|
||||
x = cast(bytes, self.table[code]) # assume not None
|
||||
self.table.append(self.prevbuf + x[:1])
|
||||
|
@ -89,10 +87,13 @@ class LZWDecoder:
|
|||
# just ignore corrupt data and stop yielding there
|
||||
break
|
||||
yield x
|
||||
assert self.table is not None
|
||||
|
||||
logger.debug(
|
||||
"nbits=%d, code=%d, output=%r, table=%r"
|
||||
% (self.nbits, code, x, self.table[258:])
|
||||
"nbits=%d, code=%d, output=%r, table=%r",
|
||||
self.nbits,
|
||||
code,
|
||||
x,
|
||||
self.table[258:],
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue