From e926ecb8b26adc8b8d6c3b6829f27efb87d86105 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Mon, 18 Apr 2016 13:08:35 -0700 Subject: [PATCH] Fuzzing: check for graphics stack overflow Very unlikely to occur --- ocrmypdf/pageinfo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ocrmypdf/pageinfo.py b/ocrmypdf/pageinfo.py index a6e13aaf..f7b9861a 100644 --- a/ocrmypdf/pageinfo.py +++ b/ocrmypdf/pageinfo.py @@ -73,11 +73,9 @@ def _shorthand_from_matrix(matrix): return tuple(map(float, (a, b, c, d, e, f))) +ContentsInfo = namedtuple('ContentsInfo', ['raster_settings', 'inline_images']) -ContentsInfo = namedtuple('ContentsInfo', - ['raster_settings', 'inline_images']) - def _interpret_contents(contentstream): operations = contentstream.operations stack = [] @@ -89,6 +87,8 @@ def _interpret_contents(contentstream): operands, command = op if command == b'q': stack.append(ctm) + if len(stack) > 32: + raise RuntimeError("PDF graphics stack overflow") elif command == b'Q': ctm = stack.pop() elif command == b'cm':