From 9059a3f1759a01a8f6df13da07780e98f5e47def Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Mon, 10 Jul 2017 21:06:30 +0930 Subject: [PATCH] Fix parsing of Type 1 fonts with newlines in encoding sequences Adobe Type 1 font spec states that the encoding sequences should be of the form: dup index /name put The bug 101728 test case has the encoding sequences in the form: dup index /name put Make the Type 1 parse handle encoding sequences split over more than one line. Bug 101728 --- fofi/FoFiType1.cc | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/fofi/FoFiType1.cc b/fofi/FoFiType1.cc index 151f2d5f..96e7c94e 100644 --- a/fofi/FoFiType1.cc +++ b/fofi/FoFiType1.cc @@ -209,12 +209,12 @@ char *FoFiType1::getNextLine(char *line) { } void FoFiType1::parse() { - char *line, *line1, *p, *p2; + char *line, *line1, *firstLine, *p, *p2; char buf[256]; char c; int n, code, base, i, j; char *tokptr; - GBool gotMatrix; + GBool gotMatrix, continueLine; gotMatrix = gFalse; for (i = 1, line = (char *)file; @@ -241,6 +241,7 @@ void FoFiType1::parse() { for (j = 0; j < 256; ++j) { encoding[j] = NULL; } + continueLine = gFalse; for (j = 0, line = getNextLine(line); j < 300 && line && (line1 = getNextLine(line)); ++j, line = line1) { @@ -248,8 +249,26 @@ void FoFiType1::parse() { error(errSyntaxWarning, -1, "FoFiType1::parse a line has more than 255 characters, we don't support this"); n = 255; } - strncpy(buf, line, n); - buf[n] = '\0'; + if (continueLine) { + continueLine = gFalse; + if ((line1 - firstLine) + 1 > (int)sizeof(buf)) + break; + p = firstLine; + p2 = buf; + while (p < line1) { + if (*p == '\n' || *p == '\r') { + *p2++ = ' '; + p++; + } else { + *p2++ = *p++; + } + } + *p2 = '\0'; + } else { + firstLine = line; + strncpy(buf, line, n); + buf[n] = '\0'; + } for (p = buf; *p == ' ' || *p == '\t'; ++p) ; if (!strncmp(p, "dup", 3)) { while (1) { @@ -261,6 +280,9 @@ void FoFiType1::parse() { p += 2; } else if (*p >= '0' && *p <= '9') { base = 10; + } else if (*p == '\n' || *p == '\r') { + continueLine = gTrue; + break; } else { break; } @@ -268,7 +290,10 @@ void FoFiType1::parse() { code = code * base + (*p - '0'); } for (; *p == ' ' || *p == '\t'; ++p) ; - if (*p != '/') { + if (*p == '\n' || *p == '\r') { + continueLine = gTrue; + break; + } else if (*p != '/') { break; } ++p; @@ -280,6 +305,10 @@ void FoFiType1::parse() { *p2 = c; } for (p = p2; *p == ' ' || *p == '\t'; ++p) ; + if (*p == '\n' || *p == '\r') { + continueLine = gTrue; + break; + } if (strncmp(p, "put", 3)) { break; } -- 2.11.0