summaryrefslogtreecommitdiff
path: root/Build/source/libs/xpdf/xpdf-src/fofi/FoFiType1.cc
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/libs/xpdf/xpdf-src/fofi/FoFiType1.cc')
-rw-r--r--Build/source/libs/xpdf/xpdf-src/fofi/FoFiType1.cc41
1 files changed, 27 insertions, 14 deletions
diff --git a/Build/source/libs/xpdf/xpdf-src/fofi/FoFiType1.cc b/Build/source/libs/xpdf/xpdf-src/fofi/FoFiType1.cc
index 4f5972a7bbb..0d067b5c5a9 100644
--- a/Build/source/libs/xpdf/xpdf-src/fofi/FoFiType1.cc
+++ b/Build/source/libs/xpdf/xpdf-src/fofi/FoFiType1.cc
@@ -99,7 +99,7 @@ void FoFiType1::writeEncoded(const char **newEncoding,
// copy everything up to the encoding
for (line = (char *)file;
- line && strncmp(line, "/Encoding", 9);
+ line && line + 9 <= (char *)file + len && strncmp(line, "/Encoding", 9);
line = getNextLine(line)) ;
if (!line) {
// no encoding - just copy the whole font file
@@ -122,7 +122,8 @@ void FoFiType1::writeEncoded(const char **newEncoding,
// find the end of the encoding data
//~ this ought to parse PostScript tokens
- if (!strncmp(line, "/Encoding StandardEncoding def", 30)) {
+ if (line + 30 <= (char *)file + len &&
+ !strncmp(line, "/Encoding StandardEncoding def", 30)) {
line = getNextLine(line);
} else {
// skip "/Encoding" + one whitespace char,
@@ -144,16 +145,18 @@ void FoFiType1::writeEncoded(const char **newEncoding,
// check for a second one here
if (line) {
for (line2 = line, i = 0;
- i < 20 && line2 && strncmp(line2, "/Encoding", 9);
+ i < 20 && line2 && line2 + 9 <= (char *)file + len &&
+ strncmp(line2, "/Encoding", 9);
line2 = getNextLine(line2), ++i) ;
if (i < 20 && line2) {
(*outputFunc)(outputStream, line, (int)(line2 - line));
- if (!strncmp(line2, "/Encoding StandardEncoding def", 30)) {
+ if (line2 + 30 <= (char *)file + len &&
+ !strncmp(line2, "/Encoding StandardEncoding def", 30)) {
line = getNextLine(line2);
} else {
- // skip "/Encoding" + one whitespace char,
+ // skip "/Encoding",
// then look for 'def' preceded by PostScript whitespace
- p = line2 + 10;
+ p = line2 + 9;
line = NULL;
for (; p < (char *)file + len; ++p) {
if ((*p == ' ' || *p == '\t' || *p == '\x0a' ||
@@ -203,9 +206,14 @@ void FoFiType1::parse() {
++i) {
// get font name
- if (!name && !strncmp(line, "/FontName", 9)) {
- strncpy(buf, line, 255);
- buf[255] = '\0';
+ if (!name && line + 9 <= (char *)file + len &&
+ !strncmp(line, "/FontName", 9)) {
+ n = 255;
+ if (line + n > (char *)file + len) {
+ n = (int)(((char *)file + len) - line);
+ }
+ strncpy(buf, line, n);
+ buf[n] = '\0';
if ((p = strchr(buf+9, '/')) &&
(p = strtok(p+1, " \t\n\r"))) {
name = copyString(p);
@@ -213,10 +221,10 @@ void FoFiType1::parse() {
line = getNextLine(line);
// get encoding
- } else if (!encoding &&
+ } else if (!encoding && line + 30 <= (char *)file + len &&
!strncmp(line, "/Encoding StandardEncoding def", 30)) {
encoding = (char **)fofiType1StandardEncoding;
- } else if (!encoding &&
+ } else if (!encoding && line + 19 <= (char *)file + len &&
!strncmp(line, "/Encoding 256 array", 19)) {
encoding = (char **)gmallocn(256, sizeof(char *));
for (j = 0; j < 256; ++j) {
@@ -284,9 +292,14 @@ void FoFiType1::parse() {
}
//~ check for getinterval/putinterval junk
- } else if (!gotMatrix && !strncmp(line, "/FontMatrix", 11)) {
- strncpy(buf, line + 11, 255);
- buf[255] = '\0';
+ } else if (!gotMatrix && line + 11 <= (char *)file + len &&
+ !strncmp(line, "/FontMatrix", 11)) {
+ n = 255;
+ if (line + 11 + n > (char *)file + len) {
+ n = (int)(((char *)file + len) - (line + 11));
+ }
+ strncpy(buf, line + 11, n);
+ buf[n] = '\0';
if ((p = strchr(buf, '['))) {
++p;
if ((p2 = strchr(p, ']'))) {