Replace this: What happened? What were you trying to achieve?
Environment
Which environment were you using when you encountered the problem?
$ python -m platform
Linux-6.16.8-arch3-1-x86_64-with-glibc2.42
$ python -c "import pypdf;print(pypdf._debug_versions)"
pypdf==6.1.1, crypt_provider=('local_crypt_fallback', '0.0.0'), PIL=none
Code + PDF
This is a minimal, complete example that shows the issue:
from pypdf import PdfReader
with open('helloworld.pdf', 'rb') as pdf_file:
PdfReader(pdf_file)
Pdf file:
helloworld.pdf
You may add it to your tests.
Traceback
This is the complete traceback I see:
entry 0 in Xref table invalid; object not found
Traceback (most recent call last):
File "/home/tyilo/pdfs/a.py", line 4, in <module>
PdfReader(pdf_file)
~~~~~~~~~^^^^^^^^^^
File "/home/tyilo/.local/share/uv/tools/pdfalyzer/lib/python3.13/site-packages/pypdf/_reader.py", line 131, in __init__
self._initialize_stream(stream)
~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
File "/home/tyilo/.local/share/uv/tools/pdfalyzer/lib/python3.13/site-packages/pypdf/_reader.py", line 153, in _initialize_stream
self.read(stream)
~~~~~~~~~^^^^^^^^
File "/home/tyilo/.local/share/uv/tools/pdfalyzer/lib/python3.13/site-packages/pypdf/_reader.py", line 604, in read
self._read_xref_tables_and_trailers(stream, startxref, xref_issue_nr)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tyilo/.local/share/uv/tools/pdfalyzer/lib/python3.13/site-packages/pypdf/_reader.py", line 860, in _read_xref_tables_and_trailers
startxref = self._read_xref(stream)
File "/home/tyilo/.local/share/uv/tools/pdfalyzer/lib/python3.13/site-packages/pypdf/_reader.py", line 898, in _read_xref
self._read_standard_xref_table(stream)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
File "/home/tyilo/.local/share/uv/tools/pdfalyzer/lib/python3.13/site-packages/pypdf/_reader.py", line 824, in _read_standard_xref_table
if entry_type_b == b"n":
^^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'entry_type_b' where it is not associated with a value
First reported here: michelcrypt4d4mus/pdfalyzer#31
Replace this: What happened? What were you trying to achieve?
Environment
Which environment were you using when you encountered the problem?
Code + PDF
This is a minimal, complete example that shows the issue:
Pdf file:
helloworld.pdf
You may add it to your tests.
Traceback
This is the complete traceback I see:
First reported here: michelcrypt4d4mus/pdfalyzer#31