aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDF_Name.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2019-08-19 03:26:19 +0200
committerJay Berkenbilt <ejb@ql.org>2019-08-20 01:48:27 +0200
commit42d396f1dd8d38294e45b14021cd72c13850a53b (patch)
treec4f0eed9ce9d048a7db7322050fd5b73d67a8d3c /libqpdf/QPDF_Name.cc
parentd9dd99eca32e44788165ce169f1e59498ad1c16e (diff)
downloadqpdf-42d396f1dd8d38294e45b14021cd72c13850a53b.tar.zst
Handle invalid name tokens symmetrically for PDF < 1.2 (fixes #332)
Diffstat (limited to 'libqpdf/QPDF_Name.cc')
-rw-r--r--libqpdf/QPDF_Name.cc10
1 files changed, 8 insertions, 2 deletions
diff --git a/libqpdf/QPDF_Name.cc b/libqpdf/QPDF_Name.cc
index 290fb067..ffd21af2 100644
--- a/libqpdf/QPDF_Name.cc
+++ b/libqpdf/QPDF_Name.cc
@@ -22,11 +22,17 @@ QPDF_Name::normalizeName(std::string const& name)
}
std::string result;
result += name.at(0);
- for (unsigned int i = 1; i < name.length(); ++i)
+ for (size_t i = 1; i < name.length(); ++i)
{
char ch = name.at(i);
// Don't use locale/ctype here; follow PDF spec guidelines.
- if (strchr("#()<>[]{}/%", ch) || (ch < 33) || (ch > 126))
+ if (ch == '\0')
+ {
+ // QPDFTokenizer embeds a null character to encode an
+ // invalid #.
+ result += "#";
+ }
+ else if (strchr("#()<>[]{}/%", ch) || (ch < 33) || (ch > 126))
{
result += "#" + QUtil::hex_encode(std::string(&ch, 1));
}