From 3eb77a700434ed6d9b51e326fa4d49c530fcd473 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Fri, 20 May 2022 09:57:30 -0400 Subject: JSON: detect duplicate dictionary keys while parsing --- include/qpdf/JSON.hh | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include') diff --git a/include/qpdf/JSON.hh b/include/qpdf/JSON.hh index e711a2df..e6857ca6 100644 --- a/include/qpdf/JSON.hh +++ b/include/qpdf/JSON.hh @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -149,6 +150,14 @@ class JSON QPDF_DLL bool isDictionary() const; + // If the key is already in the dictionary, return true. + // Otherwise, mark it has seen and return false. This is primarily + // intended to used by the parser to detect duplicate keys when + // the reactor blocks them from being added to the final + // dictionary. + QPDF_DLL + bool checkDictionaryKeySeen(std::string const& key); + // Accessors. Accessor behavior: // // - If argument is wrong type, including null, return false @@ -314,6 +323,7 @@ class JSON virtual ~JSON_dictionary() = default; virtual void write(Pipeline*, size_t depth) const; std::map> members; + std::set parsed_keys; }; struct JSON_array: public JSON_value { -- cgit v1.2.3-70-g09d2