summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/pdftexdir/tounicode.c
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/web2c/pdftexdir/tounicode.c')
-rw-r--r--Build/source/texk/web2c/pdftexdir/tounicode.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/Build/source/texk/web2c/pdftexdir/tounicode.c b/Build/source/texk/web2c/pdftexdir/tounicode.c
index 858954efde4..f90903b76c8 100644
--- a/Build/source/texk/web2c/pdftexdir/tounicode.c
+++ b/Build/source/texk/web2c/pdftexdir/tounicode.c
@@ -189,7 +189,7 @@ static char *utf16be_str(long code)
* taking into account tfmname; in case it returns
* gp->code == UNI_EXTRA_STRING then the caller is responsible for freeing
* gp->unicode_seq too */
-static void set_glyph_unicode(const char *s, const char* tfmname,
+static void set_glyph_unicode(const char *s, const char* tfmname,
glyph_unicode_entry *gp)
{
char buf[SMALL_BUF_SIZE], buf2[SMALL_BUF_SIZE], *p;
@@ -314,6 +314,19 @@ static void set_glyph_unicode(const char *s, const char* tfmname,
}
}
+static boolean is_last_byte_valid(int srcCode1, int srcCode2, long code)
+{
+ /*
+ When defining ranges of this type, the value of the last byte in the
+ string shall be less than or equal to 255 − (srcCode2 − srcCode1). This
+ ensures that the last byte of the string shall not be incremented past
+ 255; otherwise, the result of mapping is undefined.
+ */
+ char *s = strend(utf16be_str(code)) - 2;
+ long l = strtol(s, NULL, 16);
+ return l < 255 - (srcCode2 - srcCode1);
+}
+
/* tfmname is without .tfm extension, but encname ends in .enc; */
integer write_tounicode(char **glyph_names, const char *tfmname,
@@ -346,7 +359,7 @@ integer write_tounicode(char **glyph_names, const char *tfmname,
pdftex_warn("Dubious encoding file name: `%s'", encname);
} else { /* this is a builtin encoding, so name is e.g. "cmr10-builtin" */
assert(strlen(tfmname) + strlen(builtin_suffix) + 1 < SMALL_BUF_SIZE);
- strcat(buf, builtin_suffix);
+ strcat(buf, builtin_suffix);
}
objnum = pdfnewobjnum();
@@ -389,8 +402,10 @@ integer write_tounicode(char **glyph_names, const char *tfmname,
i++;
} else { /* gtab[i].code >= 0 */
j = i;
- while (i < 256 && gtab[i + 1].code >= 0 &&
- gtab[i].code + 1 == gtab[i + 1].code)
+ while (i < 256 && gtab[i + 1].code >= 0
+ && gtab[i].code + 1 == gtab[i + 1].code
+ && is_last_byte_valid(j, i, gtab[i].code)
+ )
i++;
/* at this point i is the last entry of the subrange */
i++; /* move i to the next entry */