Skip to content

Error: invalid literal for int() with base 10: b'' #925

@barchen1

Description

@barchen1

Code + PDF

I got the error for 1.pdf :

from PyPDF2 import PdfReader
from PyPDF2.generic import ArrayObject

reader = PdfReader("1.pdf")

for page_sliced in reader.pages:
    page_object = page_sliced.get_object()

    # Extracts the PDF's Annots (Annotations and Commenting):
    annots = page_object.get("/Annots")
    if annots:
        if not isinstance(annots, ArrayObject):
            annots = [annots]

        for annot in annots:
            annot_objects = annot.get_object()

And I get an error in annot.getObject() in the generic.py file when It tries to convert to int an empty byte.
Screen Shot 2022-05-29 at 16 35 37

Need to add a check that the value is not empty before converting it to an integer.

Environment

This occurs in the latest version of PyPDF2 (current master) with the following traceback:

Traceback (most recent call last):
  File "foo.py", line 16, in <module>
    annot_objects = annot.get_object()
  File "/home/moose/Github/py-pdf/PyPDF2/PyPDF2/generic.py", line 236, in get_object
    return self.pdf.get_object(self).get_object()
  File "/home/moose/Github/py-pdf/PyPDF2/PyPDF2/_reader.py", line 1099, in get_object
    retval = self._get_object_from_stream(indirect_reference)  # type: ignore
  File "/home/moose/Github/py-pdf/PyPDF2/PyPDF2/_reader.py", line 1069, in _get_object_from_stream
    obj = read_object(stream_data, self)
  File "/home/moose/Github/py-pdf/PyPDF2/PyPDF2/generic.py", line 1365, in read_object
    return NumberObject.read_from_stream(stream)
  File "/home/moose/Github/py-pdf/PyPDF2/PyPDF2/generic.py", line 386, in read_from_stream
    return NumberObject(num)
  File "/home/moose/Github/py-pdf/PyPDF2/PyPDF2/generic.py", line 356, in __new__
    val = int(value)
ValueError: invalid literal for int() with base 10: b''

Metadata

Metadata

Assignees

Labels

is-robustness-issueFrom a users perspective, this is about robustness

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions