More broadly handle RecursionError, via oss-fuzz

This commit is contained in:
Jeremy Singer-Vine
2025-03-27 21:58:17 -04:00
parent 9148810a8f
commit 748ff31dd9
3 changed files with 7 additions and 5 deletions
+1 -4
View File
@@ -348,10 +348,7 @@ class Page(Container):
parsed["data"] = annot
return parsed
try:
raw = resolve_all(self.page_obj.annots) or []
except RecursionError:
raise MalformedPDFException("Annotations are infinitely recursive.")
raw = resolve_all(self.page_obj.annots) or []
parsed = list(map(parse, raw))
if isinstance(self, CroppedPage):
return self._crop_fn(parsed)
+6 -1
View File
@@ -4,6 +4,8 @@ from pdfminer.pdftypes import PDFObjRef
from pdfminer.psparser import PSLiteral
from pdfminer.utils import PDFDocEncoding
from .exceptions import MalformedPDFException
def decode_text(s: Union[bytes, str]) -> str:
"""
@@ -72,7 +74,10 @@ def resolve_all(x: Any) -> Any:
if get_dict_type(resolved) == "Page":
return x
return resolve_all(resolved)
try:
return resolve_all(resolved)
except RecursionError as e:
raise MalformedPDFException(e)
elif isinstance(x, (list, tuple)):
return type(x)(resolve_all(v) for v in x)
elif isinstance(x, dict):
Binary file not shown.