Discard duplication key/value pairs in dictionaries with a warning message (Issue #118)

This commit is contained in:
Michael R Sweet 2025-04-07 08:58:18 -04:00
parent d7eb1fc540
commit 49efd97cab
No known key found for this signature in database
GPG Key ID: BE67C75EC81F3244
2 changed files with 11 additions and 7 deletions

View File

@ -6,6 +6,8 @@ v1.5.2 - YYYY-MM-DD
------------------- -------------------
- Updated maximum allowed PDF string size to 64k (Issue #117) - 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 form detection in `pdfioinfo` example code (Issue #114)
- Fixed parsing of certain date/time values (Issue #115) - Fixed parsing of certain date/time values (Issue #115)
- Fixed support for empty name values (Issue #116) - Fixed support for empty name values (Issue #116)

View File

@ -737,11 +737,6 @@ _pdfioDictRead(pdfio_file_t *pdf, // I - PDF file
_pdfioFileError(pdf, "Invalid dictionary contents."); _pdfioFileError(pdf, "Invalid dictionary contents.");
break; break;
} }
else if (_pdfioDictGetValue(dict, key + 1))
{
_pdfioFileError(pdf, "Duplicate dictionary key '%s'.", key + 1);
return (NULL);
}
// Then get the next value... // Then get the next value...
PDFIO_DEBUG("_pdfioDictRead: Reading value for '%s'.\n", key + 1); 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); _pdfioFileError(pdf, "Missing value for dictionary key '%s'.", key + 1);
break; break;
} }
else if (_pdfioDictGetValue(dict, key + 1))
if (!_pdfioDictSetValue(dict, pdfioStringCreate(pdf, key + 1), &value)) {
// 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; break;
PDFIO_DEBUG("_pdfioDictRead: Set %s.\n", key); PDFIO_DEBUG("_pdfioDictRead: Set %s.\n", key);