From 1d39d9d10c7fa83bb509e50ab135f5f97c2810eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20B=C3=BCnzli?= Date: Fri, 18 Jul 2014 15:21:09 +0200 Subject: hex-encode UTF-16 strings when writing PDF fmt_obj calculates whether a string is better hex-encoded or written using escapes. Due to a bug, '\0' is considered to be escapable same as '\n' when instead it would have to be written as '\000'. Since UTF-16 strings tend to consist of many '\0' bytes, their octal encoded form is much longer than their hex encoded form. The issue is that the first argument to strchr contains an unintended trailing '\0' which has to be special-cased first. --- source/pdf/pdf-object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source') diff --git a/source/pdf/pdf-object.c b/source/pdf/pdf-object.c index 51272dea..1b7a5aa9 100644 --- a/source/pdf/pdf-object.c +++ b/source/pdf/pdf-object.c @@ -1672,7 +1672,7 @@ static void fmt_obj(struct fmt *fmt, pdf_obj *obj) int i, c; for (i = 0; i < len; i++) { c = (unsigned char)str[i]; - if (strchr("()\\\n\r\t\b\f", c)) + if (c != 0 && strchr("()\\\n\r\t\b\f", c)) added ++; else if (c < 32 || c >= 127) added += 3; -- cgit v1.2.3