aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDF_json.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-05-20 14:11:14 +0200
committerJay Berkenbilt <ejb@ql.org>2022-05-20 15:16:25 +0200
commit35b1e1c4936903ebb841ed89945ea55fe95e0abb (patch)
tree904b1686e8ab4729dde9417e6893b5e365b1748a /libqpdf/QPDF_json.cc
parentdc8df962d8f0d93595a4e036bb29bc3498abc35f (diff)
downloadqpdf-35b1e1c4936903ebb841ed89945ea55fe95e0abb.tar.zst
Explicitly test ignoring unknown keys in JSON input
Diffstat (limited to 'libqpdf/QPDF_json.cc')
-rw-r--r--libqpdf/QPDF_json.cc25
1 files changed, 10 insertions, 15 deletions
diff --git a/libqpdf/QPDF_json.cc b/libqpdf/QPDF_json.cc
index c421ce41..b7fe4368 100644
--- a/libqpdf/QPDF_json.cc
+++ b/libqpdf/QPDF_json.cc
@@ -170,7 +170,7 @@ QPDF::JSONReactor::containerEnd(JSON const& value)
}
} else if (state == st_objects) {
if (parse_error) {
- // ignore
+ QTC::TC("qpdf", "QPDF_json don't check object after parse error");
} else if (cur_object == "trailer") {
if (!saw_value) {
QTC::TC("qpdf", "QPDF_json trailer no value");
@@ -279,9 +279,9 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value)
this->saw_qpdf = true;
nestedState(key, value, st_qpdf);
} else {
- // Ignore all other fields for forward compatibility.
- // Don't use nestedState since this can be any type.
- // QXXXQ QTC
+ // Ignore all other fields. We explicitly allow people to
+ // add other top-level keys for their own use.
+ QTC::TC("qpdf", "QPDF_json ignoring unknown top-level key");
next_state = st_ignore;
}
} else if (state == st_qpdf) {
@@ -304,8 +304,9 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value)
this->saw_objects = true;
nestedState(key, value, st_objects);
} else {
- // ignore unknown keys for forward compatibility
- // QXXXQ QTC
+ // ignore unknown keys for forward compatibility and to
+ // skip keys we don't care about like "maxobjectid".
+ QTC::TC("qpdf", "QPDF_json ignore second-level key");
next_state = st_ignore;
}
} else if (state == st_objects) {
@@ -351,7 +352,7 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value)
}
} else {
// Ignore unknown keys for forward compatibility
- // QXXXQ QTC
+ QTC::TC("qpdf", "QPDF_json ignore unknown key in object_top");
next_state = st_ignore;
}
if (replacement.isInitialized()) {
@@ -373,7 +374,7 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value)
parse_error = true;
} else {
// Ignore unknown keys for forward compatibility
- // QXXXQ QTC
+ QTC::TC("qpdf", "QPDF_json ignore unknown key in trailer");
next_state = st_ignore;
}
} else if (state == st_stream) {
@@ -430,7 +431,7 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value)
}
} else {
// Ignore unknown keys for forward compatibility.
- // QXXXQ QTC
+ QTC::TC("qpdf", "QPDF_json ignore unknown key in stream");
next_state = st_ignore;
}
} else if (state == st_object) {
@@ -549,12 +550,6 @@ QPDF::importJSON(std::shared_ptr<InputSource> is, bool must_be_complete)
if (reactor.anyErrors()) {
throw std::runtime_error(is->getName() + ": errors found in JSON");
}
- // QXXXQ
- // std::cout << "trailer:\n" << getTrailer().unparse() << std::endl;
- // for (auto& oh: getAllObjects()) {
- // std::cout << oh.unparse() << ":" << std::endl;
- // std::cout << oh.unparseResolved() << std::endl;
- // }
}
void