diff options
author | Jay Berkenbilt <ejb@ql.org> | 2019-08-19 03:26:19 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2019-08-20 01:48:27 +0200 |
commit | 42d396f1dd8d38294e45b14021cd72c13850a53b (patch) | |
tree | c4f0eed9ce9d048a7db7322050fd5b73d67a8d3c /libqpdf/QPDF_Name.cc | |
parent | d9dd99eca32e44788165ce169f1e59498ad1c16e (diff) | |
download | qpdf-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.cc | 10 |
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)); } |