ietf-tools / xml2rfc

Generate RFCs and IETF drafts from document source in XML according to the IETF xml2rfc v2 and v3 vocabularies
https://ietf-tools.github.io/xml2rfc/
BSD 3-Clause "New" or "Revised" License
63 stars 35 forks source link

Infinite Recursion With PyPDF 4.1.0 #1111

Closed kitterma closed 4 months ago

kitterma commented 4 months ago

Describe the issue

When I run the xml2rfc tests with the new pypdf release, there is an infinite recursion error. Here's an excerpt from the test log:

115s autopkgtest [09:16:38]: test run-pytest: [-----------------------
116s Testing with python3.12:
135s ..E..............................................
135s ======================================================================
135s ERROR: setUpClass (__main__.PdfWriterTests)
135s ----------------------------------------------------------------------
135s Traceback (most recent call last):
135s   File "/tmp/autopkgtest-lxc.gvxbgwgc/downtmp/build.QrX/src/xxx/test.py", line 496, in setUpClass
135s     cls.elements_pdfxml = xmldoc(None, bytes=elements_pdfdoc)
135s                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
135s   File "/usr/lib/python3/dist-packages/xml2rfc/walkpdf.py", line 96, in xmldoc
135s     text = xmltext(filename=filename, bytes=bytes)
135s            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
135s   File "/usr/lib/python3/dist-packages/xml2rfc/walkpdf.py", line 89, in xmltext
135s     obj = pyobj(filename=filename, bytes=bytes)
135s           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
135s   File "/usr/lib/python3/dist-packages/xml2rfc/walkpdf.py", line 77, in pyobj
135s     d, i = walk(obj, seen)
135s            ^^^^^^^^^^^^^^^
135s   File "/usr/lib/python3/dist-packages/xml2rfc/walkpdf.py", line 21, in walk
135s     d, i = walk(obj[key], seen)
135s            ^^^^^^^^^^^^^^^^^^^^
135s   File "/usr/lib/python3/dist-packages/xml2rfc/walkpdf.py", line 21, in walk
135s     d, i = walk(obj[key], seen)
135s            ^^^^^^^^^^^^^^^^^^^^
135s   File "/usr/lib/python3/dist-packages/xml2rfc/walkpdf.py", line 29, in walk
The last three lines repeat until you get to the recursion limit:
135s   File "/usr/lib/python3/dist-packages/pypdf/generic/_base.py", line 301, in __getattr__
135s     return getattr(self._get_object_with_check(), name)
135s                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
135s   File "/usr/lib/python3/dist-packages/pypdf/generic/_base.py", line 290, in _get_object_with_check
135s     o = self.get_object()
135s         ^^^^^^^^^^^^^^^^^
135s RecursionError: maximum recursion depth exceeded
135s 
135s ----------------------------------------------------------------------
135s Ran 48 tests in 18.098s

This is with Python 3.12.

Code of Conduct

kitterma commented 4 months ago

Suggested fix from PyPDF upstream. I will test and report back.

https://github.com/py-pdf/pypdf/issues/2508#issuecomment-1986477432

kitterma commented 4 months ago

I tested this and it works. I'm not going to prepare a PR as I'm not sure what to do about the required version. PyPDF appears to be missing from requirements.

kesara commented 4 months ago

@kitterma Thank you for flagging this out and finding a solution.

PyPDF is only used for testing so its version is defined in tox.ini ^1.

kitterma commented 4 months ago

On March 10, 2024 8:52:47 PM UTC, Kesara Rathnayake @.***> wrote:

@kitterma Thank you for flagging this out and finding a solution.

PyPDF is only used for testing so its version is defined in tox.ini ^1.

Thanks. Since I submitted this, I tested it with PyPDF 4.0.2 and it works with it too, so no version bump is needed.