summaryrefslogtreecommitdiff
path: root/pdf/pdf_parse.c
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2012-08-06 00:13:41 +0200
committerSebastian Rasmussen <sebras@gmail.com>2012-08-06 14:05:39 +0200
commit8f1909597745d2c881f1cacfff7e0a72eb233438 (patch)
tree4232cfba73caa52747f991a6931b21f6ebe308cf /pdf/pdf_parse.c
parent30cea356bb6b5038e7eee642eccb8cf185945a40 (diff)
downloadmupdf-8f1909597745d2c881f1cacfff7e0a72eb233438.tar.xz
Throw exception on too deeply nested arrays/dicts
Previously we would run out of error stacks in the context and fail abruptly. Now, throw an exception and hope for the best. At least this plugs any memory leaks.
Diffstat (limited to 'pdf/pdf_parse.c')
-rw-r--r--pdf/pdf_parse.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/pdf/pdf_parse.c b/pdf/pdf_parse.c
index 0ba6b0a4..4ed6b6f1 100644
--- a/pdf/pdf_parse.c
+++ b/pdf/pdf_parse.c
@@ -244,6 +244,9 @@ pdf_parse_array(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf)
break;
case PDF_TOK_OPEN_ARRAY:
+ if (fz_too_deeply_nested(ctx))
+ fz_throw(ctx, "nested too deep, not parsing array");
+
obj = pdf_parse_array(xref, file, buf);
pdf_array_push(ary, obj);
pdf_drop_obj(obj);
@@ -251,6 +254,9 @@ pdf_parse_array(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf)
break;
case PDF_TOK_OPEN_DICT:
+ if (fz_too_deeply_nested(ctx))
+ fz_throw(ctx, "nested too deep, not parsing dict");
+
obj = pdf_parse_dict(xref, file, buf);
pdf_array_push(ary, obj);
pdf_drop_obj(obj);
@@ -348,10 +354,16 @@ pdf_parse_dict(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf)
switch (tok)
{
case PDF_TOK_OPEN_ARRAY:
+ if (fz_too_deeply_nested(ctx))
+ fz_throw(ctx, "nested too deep, not parsing array");
+
val = pdf_parse_array(xref, file, buf);
break;
case PDF_TOK_OPEN_DICT:
+ if (fz_too_deeply_nested(ctx))
+ fz_throw(ctx, "nested too deep, not parsing array");
+
val = pdf_parse_dict(xref, file, buf);
break;