From 49efd97cabd78aa085f1e208234a495e0d2e8c46 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Mon, 7 Apr 2025 08:58:18 -0400 Subject: [PATCH] Discard duplication key/value pairs in dictionaries with a warning message (Issue #118) --- CHANGES.md | 2 ++ pdfio-dict.c | 16 +++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9f06329..52f8511 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,8 @@ v1.5.2 - YYYY-MM-DD ------------------- - Updated maximum allowed PDF string size to 64k (Issue #117) +- Updated dictionary reading code to discard duplicate key/value pairs with a + warning message (Issue #118) - Fixed form detection in `pdfioinfo` example code (Issue #114) - Fixed parsing of certain date/time values (Issue #115) - Fixed support for empty name values (Issue #116) diff --git a/pdfio-dict.c b/pdfio-dict.c index f8aadc6..2ea63de 100644 --- a/pdfio-dict.c +++ b/pdfio-dict.c @@ -737,11 +737,6 @@ _pdfioDictRead(pdfio_file_t *pdf, // I - PDF file _pdfioFileError(pdf, "Invalid dictionary contents."); break; } - else if (_pdfioDictGetValue(dict, key + 1)) - { - _pdfioFileError(pdf, "Duplicate dictionary key '%s'.", key + 1); - return (NULL); - } // Then get the next value... PDFIO_DEBUG("_pdfioDictRead: Reading value for '%s'.\n", key + 1); @@ -751,8 +746,15 @@ _pdfioDictRead(pdfio_file_t *pdf, // I - PDF file _pdfioFileError(pdf, "Missing value for dictionary key '%s'.", key + 1); break; } - - if (!_pdfioDictSetValue(dict, pdfioStringCreate(pdf, key + 1), &value)) + else if (_pdfioDictGetValue(dict, key + 1)) + { + // Issue 118: Discard duplicate key/value pairs, in the future this will + // be a warning message... + _pdfioFileError(pdf, "WARNING: Discarding value for duplicate dictionary key '%s'.", key + 1); + _pdfioValueDelete(&value); + continue; + } + else if (!_pdfioDictSetValue(dict, pdfioStringCreate(pdf, key + 1), &value)) break; PDFIO_DEBUG("_pdfioDictRead: Set %s.\n", key);