PyPDF4 icon indicating copy to clipboard operation
PyPDF4 copied to clipboard

ASCIIHexCodec decoder not compatible with bytes object

Open dcmvdbekerom opened this issue 5 years ago • 0 comments

An exception is thrown when decoding objects with a ASCIIHEXCodec:

    fdata = fobj.getData()
  File "c:\users\dcmvd\documents\github\pypdf4\pypdf\generic.py", line 950, in getData
    decoded._data = decodeStreamData(self)
  File "c:\users\dcmvd\documents\github\pypdf4\pypdf\filters.py", line 757, in decodeStreamData
    data = ASCIIHexCodec.decode(data)
  File "c:\users\dcmvd\documents\github\pypdf4\pypdf\filters.py", line 249, in decode
    elif c.isspace():
AttributeError: 'int' object has no attribute 'isspace'

This is likely legacy Py2 code that was not updated to Py3. The problem can be solved easily by converting data to string in the beginning of the method:

 try:
       data = data.decode()
 except(AttributeError):
       pass

And converting the return value to str/byte depending on which python version is running at the end of the method:

retval = b_(retval)

dcmvdbekerom avatar Jun 29 '20 02:06 dcmvdbekerom