Skip to content

Commit

Permalink
fix: handle some invalid PDF cases
Browse files Browse the repository at this point in the history
  • Loading branch information
dhdaines committed Sep 19, 2024
1 parent c0fc003 commit 2c468dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion playa/pdfparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ def flush(self) -> None:
def do_keyword(self, pos: int, token: PSKeyword) -> None:
if token is KEYWORD_R:
# reference to indirect object
(_, _object_id), _ = self.pop(2)
try:
(_, _object_id), _ = self.pop(2)
except ValueError:
raise PDFSyntaxError(
"Expected generation and object id in indirect object reference"
)
object_id = safe_int(_object_id)
if object_id is not None:
obj = PDFObjRef(self.doc, object_id)
Expand Down
4 changes: 3 additions & 1 deletion playa/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
cast,
)

from playa.exceptions import PDFTypeError, PDFValueError
from playa.exceptions import PDFSyntaxError, PDFTypeError, PDFValueError

if TYPE_CHECKING:
from playa.layout import LTComponent
Expand Down Expand Up @@ -246,6 +246,8 @@ def parse_rect(o: Any) -> Rect:
return float(x0), float(y0), float(x1), float(y1)
except ValueError:
raise PDFValueError("Could not parse rectangle")
except TypeError:
raise PDFSyntaxError("Rectangle contains non-numeric values")


def mult_matrix(m1: Matrix, m0: Matrix) -> Matrix:
Expand Down

0 comments on commit 2c468dc

Please sign in to comment.