Warn for duplicated dictionary keys (fixes #345)

This commit is contained in:
Jay Berkenbilt 2019-09-19 20:22:34 -04:00
parent 5ce287d6bb
commit 8b1e307741
8 changed files with 27 additions and 2 deletions

View File

@ -1,3 +1,10 @@
2019-09-19 Jay Berkenbilt <ejb@ql.org>
* Warn when duplicated dictionary keys are found during parsing.
The behavior remains as before: later keys override earlier ones.
However, this generates a warning now rather than being silently
ignored. Fixes #345.
2019-09-17 Jay Berkenbilt <ejb@ql.org>
* QIntC tests: don't assume char is signed. Fixes #361.

View File

@ -2135,7 +2135,18 @@ QPDFObjectHandle::parseInternal(PointerHolder<InputSource> input,
{
val = olist.at(++i);
}
dict[key_obj.getName()] = val;
std::string key = key_obj.getName();
if (dict.count(key) > 0)
{
QTC::TC("qpdf", "QPDFObjectHandle duplicate dict key");
warn(context,
QPDFExc(
qpdf_e_damaged_pdf,
input->getName(), object_description, offset,
"dictionary has duplicated key " + key +
"; last occurrence overrides earlier ones"));
}
dict[key] = val;
}
object = newDictionary(dict);
setObjectDescriptionFromInput(

View File

@ -445,3 +445,4 @@ QPDF eof skipping spaces before xref 1
QPDF_encryption user matches owner V < 5 0
QPDF_encryption same password 1
QPDFWriter stream in ostream 0
QPDFObjectHandle duplicate dict key 0

View File

@ -2314,7 +2314,7 @@ my @badfiles = ("not a PDF file", # 1
"bad }", # 14
"bad ]", # 15
"bad >>", # 16
"odd number of dictionary items", # 17
"dictionary errors", # 17
"bad )", # 18
"bad >", # 19
"invalid hexstring character", # 20

View File

@ -1,3 +1,4 @@
WARNING: bad17.pdf (trailer, offset 715): dictionary has duplicated key /K; last occurrence overrides earlier ones
WARNING: bad17.pdf (trailer, offset 715): dictionary ended prematurely; using null as value for last key
/QTest is implicit
/QTest is direct and has type null (2)

View File

@ -1,3 +1,4 @@
WARNING: bad17.pdf (trailer, offset 715): dictionary has duplicated key /K; last occurrence overrides earlier ones
WARNING: bad17.pdf (trailer, offset 715): dictionary ended prematurely; using null as value for last key
/QTest is implicit
/QTest is direct and has type null (2)

View File

@ -73,6 +73,8 @@ xref
trailer <<
/Size 7
/Root 1 0 R
/K 1
/K 2
/Something
>>
startxref

View File

@ -1,6 +1,8 @@
WARNING: issue-51.pdf: can't find PDF header
WARNING: issue-51.pdf: reported number of objects (0) is not one plus the highest object number (8)
WARNING: issue-51.pdf (object 7 0, offset 476): dictionary has duplicated key /0000; last occurrence overrides earlier ones
WARNING: issue-51.pdf (object 7 0, offset 553): expected endobj
WARNING: issue-51.pdf (object 1 0, offset 236): dictionary has duplicated key /00000000; last occurrence overrides earlier ones
WARNING: issue-51.pdf (object 1 0, offset 359): expected endobj
WARNING: issue-51.pdf (offset 70): loop detected resolving object 2 0
WARNING: issue-51.pdf (object 2 0, offset 26): /Length key in stream dictionary is not an integer