claird / PyPDF4

A utility to read and write PDFs with Python
obsolete-https://pythonhosted.org/PyPDF2/
Other
328 stars 61 forks source link

`pypdfChr()` may throw a TypeError or return the wrong type #42

Closed kurtmckee closed 5 years ago

kurtmckee commented 5 years ago

In Python 3, if pypdfChr() is provided an input that is either a bytes or str object it will throw a TypeError.

And in Python 2, if pypdfChr() is provided an int or unicode object it will quietly return the same object type (int or unicode).

This is a problem because code that interacts with a bytes string in a loop, or accesses a bytes string by index, the individual character will be a str in Python 2 but an int in Python 3. And if the string type is not 100% known (that is, perhaps it's unicode in Python 2 or str in Python 3), then the same loop or index-based access may be passed into pypdfChr(), causing a crash or an incorrect type to be returned.