summaryrefslogtreecommitdiff
path: root/source/pdf
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2017-06-28 02:15:30 +0800
committerSebastian Rasmussen <sebras@gmail.com>2017-07-06 22:30:54 +0800
commitb0533a00efd919840d3712847c386084308538a0 (patch)
treebf074ecf53d04ec61075baea1f700ac6bb7a8447 /source/pdf
parentb235f6d80e5c9d1beb7e02fb444d72f0475555d2 (diff)
downloadmupdf-b0533a00efd919840d3712847c386084308538a0.tar.xz
pdf: Avoid leaking indirect object upon error.
Diffstat (limited to 'source/pdf')
-rw-r--r--source/pdf/pdf-parse.c64
1 files changed, 34 insertions, 30 deletions
diff --git a/source/pdf/pdf-parse.c b/source/pdf/pdf-parse.c
index fc1503bb..e75baa60 100644
--- a/source/pdf/pdf-parse.c
+++ b/source/pdf/pdf-parse.c
@@ -589,6 +589,7 @@ pdf_parse_ind_obj(fz_context *ctx, pdf_document *doc,
fz_off_t stm_ofs;
pdf_token tok;
fz_off_t a, b;
+ int read_next_token = 1;
fz_var(obj);
@@ -644,9 +645,10 @@ pdf_parse_ind_obj(fz_context *ctx, pdf_document *doc,
if (tok == PDF_TOK_STREAM || tok == PDF_TOK_ENDOBJ)
{
obj = pdf_new_int_offset(ctx, doc, a);
- goto skip;
+ read_next_token = 0;
+ break;
}
- if (tok == PDF_TOK_INT)
+ else if (tok == PDF_TOK_INT)
{
b = buf->i;
tok = pdf_lex(ctx, file, buf);
@@ -660,7 +662,8 @@ pdf_parse_ind_obj(fz_context *ctx, pdf_document *doc,
case PDF_TOK_ENDOBJ:
obj = pdf_new_null(ctx, doc);
- goto skip;
+ read_next_token = 0;
+ break;
default:
fz_throw(ctx, FZ_ERROR_SYNTAX, "syntax error in object (%d %d R)", num, gen);
@@ -668,42 +671,43 @@ pdf_parse_ind_obj(fz_context *ctx, pdf_document *doc,
fz_try(ctx)
{
- tok = pdf_lex(ctx, file, buf);
- }
- fz_catch(ctx)
- {
- pdf_drop_obj(ctx, obj);
- fz_rethrow(ctx);
- }
+ if (read_next_token)
+ tok = pdf_lex(ctx, file, buf);
-skip:
- if (tok == PDF_TOK_STREAM)
- {
- int c = fz_read_byte(ctx, file);
- while (c == ' ')
- c = fz_read_byte(ctx, file);
- if (c == '\r')
+ if (tok == PDF_TOK_STREAM)
{
- c = fz_peek_byte(ctx, file);
- if (c != '\n')
- fz_warn(ctx, "line feed missing after stream begin marker (%d %d R)", num, gen);
- else
- fz_read_byte(ctx, file);
+ int c = fz_read_byte(ctx, file);
+ while (c == ' ')
+ c = fz_read_byte(ctx, file);
+ if (c == '\r')
+ {
+ c = fz_peek_byte(ctx, file);
+ if (c != '\n')
+ fz_warn(ctx, "line feed missing after stream begin marker (%d %d R)", num, gen);
+ else
+ fz_read_byte(ctx, file);
+ }
+ stm_ofs = fz_tell(ctx, file);
+ }
+ else if (tok == PDF_TOK_ENDOBJ)
+ {
+ stm_ofs = 0;
+ }
+ else
+ {
+ fz_warn(ctx, "expected 'endobj' or 'stream' keyword (%d %d R)", num, gen);
+ stm_ofs = 0;
}
- stm_ofs = fz_tell(ctx, file);
- }
- else if (tok == PDF_TOK_ENDOBJ)
- {
- stm_ofs = 0;
}
- else
+ fz_catch(ctx)
{
- fz_warn(ctx, "expected 'endobj' or 'stream' keyword (%d %d R)", num, gen);
- stm_ofs = 0;
+ pdf_drop_obj(ctx, obj);
+ fz_rethrow(ctx);
}
if (onum) *onum = num;
if (ogen) *ogen = gen;
if (ostmofs) *ostmofs = stm_ofs;
+
return obj;
}