diff options
-rw-r--r-- | source/pdf/pdf-lex.c | 27 | ||||
-rw-r--r-- | source/pdf/pdf-parse.c | 10 |
2 files changed, 28 insertions, 9 deletions
diff --git a/source/pdf/pdf-lex.c b/source/pdf/pdf-lex.c index 44c685578..fc439d17a 100644 --- a/source/pdf/pdf-lex.c +++ b/source/pdf/pdf-lex.c | |||
@@ -151,12 +151,21 @@ lex_number(fz_context *ctx, fz_stream *f, pdf_lexbuf *buf, int c) | |||
151 | char *e = buf->scratch + buf->size - 1; /* leave space for zero terminator */ | 151 | char *e = buf->scratch + buf->size - 1; /* leave space for zero terminator */ |
152 | char *isreal = (c == '.' ? s : NULL); | 152 | char *isreal = (c == '.' ? s : NULL); |
153 | int neg = (c == '-'); | 153 | int neg = (c == '-'); |
154 | int isbad = 0; | ||
154 | 155 | ||
155 | *s++ = c; | 156 | *s++ = c; |
156 | 157 | ||
158 | c = fz_read_byte(ctx, f); | ||
159 | |||
160 | /* skip extra '-' signs at start of number */ | ||
161 | if (neg) | ||
162 | { | ||
163 | while (c == '-') | ||
164 | c = fz_read_byte(ctx, f); | ||
165 | } | ||
166 | |||
157 | while (s < e) | 167 | while (s < e) |
158 | { | 168 | { |
159 | c = fz_read_byte(ctx, f); | ||
160 | switch (c) | 169 | switch (c) |
161 | { | 170 | { |
162 | case IS_WHITE: | 171 | case IS_WHITE: |
@@ -165,21 +174,27 @@ lex_number(fz_context *ctx, fz_stream *f, pdf_lexbuf *buf, int c) | |||
165 | goto end; | 174 | goto end; |
166 | case EOF: | 175 | case EOF: |
167 | goto end; | 176 | goto end; |
168 | case '-': | ||
169 | neg++; | ||
170 | *s++ = c; | ||
171 | break; | ||
172 | case '.': | 177 | case '.': |
178 | if (isreal) | ||
179 | isbad = 1; | ||
173 | isreal = s; | 180 | isreal = s; |
174 | /* Fall through */ | 181 | *s++ = c; |
182 | break; | ||
183 | case RANGE_0_9: | ||
184 | *s++ = c; | ||
185 | break; | ||
175 | default: | 186 | default: |
187 | isbad = 1; | ||
176 | *s++ = c; | 188 | *s++ = c; |
177 | break; | 189 | break; |
178 | } | 190 | } |
191 | c = fz_read_byte(ctx, f); | ||
179 | } | 192 | } |
180 | 193 | ||
181 | end: | 194 | end: |
182 | *s = '\0'; | 195 | *s = '\0'; |
196 | if (isbad) | ||
197 | return PDF_TOK_ERROR; | ||
183 | if (isreal) | 198 | if (isreal) |
184 | { | 199 | { |
185 | /* We'd like to use the fastest possible atof | 200 | /* We'd like to use the fastest possible atof |
diff --git a/source/pdf/pdf-parse.c b/source/pdf/pdf-parse.c index 451d9e1df..ff741dcbf 100644 --- a/source/pdf/pdf-parse.c +++ b/source/pdf/pdf-parse.c | |||
@@ -457,7 +457,8 @@ pdf_parse_array(fz_context *ctx, pdf_document *doc, fz_stream *file, pdf_lexbuf | |||
457 | break; | 457 | break; |
458 | 458 | ||
459 | default: | 459 | default: |
460 | fz_throw(ctx, FZ_ERROR_SYNTAX, "cannot parse token in array"); | 460 | pdf_array_push_drop(ctx, ary, pdf_new_null(ctx, doc)); |
461 | break; | ||
461 | } | 462 | } |
462 | } | 463 | } |
463 | end: | 464 | end: |
@@ -547,10 +548,13 @@ pdf_parse_dict(fz_context *ctx, pdf_document *doc, fz_stream *file, pdf_lexbuf * | |||
547 | break; | 548 | break; |
548 | } | 549 | } |
549 | } | 550 | } |
550 | fz_throw(ctx, FZ_ERROR_SYNTAX, "invalid indirect reference in dict"); | 551 | fz_warn(ctx, "invalid indirect reference in dict"); |
552 | val = pdf_new_null(ctx, doc); | ||
553 | break; | ||
551 | 554 | ||
552 | default: | 555 | default: |
553 | fz_throw(ctx, FZ_ERROR_SYNTAX, "unknown token in dict"); | 556 | val = pdf_new_null(ctx, doc); |
557 | break; | ||
554 | } | 558 | } |
555 | 559 | ||
556 | pdf_dict_put(ctx, dict, key, val); | 560 | pdf_dict_put(ctx, dict, key, val); |