summaryrefslogtreecommitdiff
path: root/Build/source/texk/xdvipdfmx/src/pdfdev.c
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/xdvipdfmx/src/pdfdev.c')
-rw-r--r--Build/source/texk/xdvipdfmx/src/pdfdev.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/Build/source/texk/xdvipdfmx/src/pdfdev.c b/Build/source/texk/xdvipdfmx/src/pdfdev.c
index e74a60f7296..24727d12944 100644
--- a/Build/source/texk/xdvipdfmx/src/pdfdev.c
+++ b/Build/source/texk/xdvipdfmx/src/pdfdev.c
@@ -918,17 +918,32 @@ handle_multibyte_string (struct dev_font *font,
}
length *= 4;
} else if (ctype == 2) {
+ int len = 0;
+
if (length * 2 >= FORMAT_BUF_SIZE) {
WARN("Too long string...");
return -1;
}
- for (i = 0; i < length; i += 2) {
- sbuf1[i*2 ] = font->ucs_group;
- sbuf1[i*2+1] = font->ucs_plane;
- sbuf1[i*2+2] = p[i];
- sbuf1[i*2+3] = p[i+1];
+ for (i = 0; i < length; i += 2, len += 4) {
+ sbuf1[len ] = font->ucs_group;
+ if ((p[i] & 0xf8) == 0xd8) {
+ int c;
+ /* Check for valid surrogate pair. */
+ if ((p[i] & 0xfc) != 0xd8 || i + 2 >= length || (p[i+2] & 0xfc) != 0xdc) {
+ WARN("Invalid surrogate p[%d]=%02X...", i, p[i]);
+ return -1;
+ }
+ c = (((p[i] & 0x03) << 10) | (p[i+1] << 2) | (p[i+2] & 0x03)) + 0x100;
+ sbuf1[len+1] = (c >> 8) & 0xff;
+ sbuf1[len+2] = c & 0xff;
+ i += 2;
+ } else {
+ sbuf1[len+1] = font->ucs_plane;
+ sbuf1[len+2] = p[i];
+ }
+ sbuf1[len+3] = p[i+1];
}
- length *= 2;
+ length = len;
}
p = sbuf1;
} else if (ctype == 1 && font->mapc >= 0) {