summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2017-09-22 17:39:56 +0200
committerTor Andersson <tor.andersson@artifex.com>2017-09-22 17:49:45 +0200
commit9c83cbb80b08dadb575c62790e4084f04307a2e5 (patch)
tree61f8c8ef9d54a94166fefb84ee1d4e12cbe23a4e
parentd2446f9005b58ebdf03b99a6d57034031269ac09 (diff)
downloadmupdf-9c83cbb80b08dadb575c62790e4084f04307a2e5.tar.xz
Skip to next whitespace character instead of aborting when repairing PDF.
-rw-r--r--source/pdf/pdf-lex.c2
-rw-r--r--source/pdf/pdf-repair.c14
2 files changed, 11 insertions, 5 deletions
diff --git a/source/pdf/pdf-lex.c b/source/pdf/pdf-lex.c
index 34b08133..c823dca7 100644
--- a/source/pdf/pdf-lex.c
+++ b/source/pdf/pdf-lex.c
@@ -7,7 +7,7 @@
'+':case'-':case'.':case'0':case'1':case'2':case'3':\
case'4':case'5':case'6':case'7':case'8':case'9'
#define IS_WHITE \
- '\000':case'\011':case'\012':case'\014':case'\015':case'\040'
+ '\x00':case'\x09':case'\x0a':case'\x0c':case'\x0d':case'\x20'
#define IS_HEX \
'0':case'1':case'2':case'3':case'4':case'5':case'6':\
case'7':case'8':case'9':case'A':case'B':case'C':\
diff --git a/source/pdf/pdf-repair.c b/source/pdf/pdf-repair.c
index 4e8b4bdf..29d11e55 100644
--- a/source/pdf/pdf-repair.c
+++ b/source/pdf/pdf-repair.c
@@ -285,6 +285,11 @@ orphan_object(fz_context *ctx, pdf_document *doc, pdf_obj *obj)
doc->orphans[doc->orphans_count++] = obj;
}
+static int is_white(int c)
+{
+ return c == '\x00' || c == '\x09' || c == '\x0a' || c == '\x0c' || c == '\x0d' || c == '\x20';
+}
+
void
pdf_repair_xref(fz_context *ctx, pdf_document *doc)
{
@@ -373,14 +378,15 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot tell in file");
fz_try(ctx)
- {
tok = pdf_lex_no_string(ctx, doc->file, buf);
- }
fz_catch(ctx)
{
fz_rethrow_if(ctx, FZ_ERROR_TRYLATER);
- fz_warn(ctx, "ignoring the rest of the file");
- break;
+ fz_warn(ctx, "skipping ahead to next token");
+ do
+ c = fz_read_byte(ctx, doc->file);
+ while (c != EOF && !is_white(c));
+ continue;
}
/* If we have the next token already, then we'll jump