diff --git a/libqpdf/JSON.cc b/libqpdf/JSON.cc index 4ea3507b..5950f920 100644 --- a/libqpdf/JSON.cc +++ b/libqpdf/JSON.cc @@ -671,6 +671,7 @@ namespace qpdf_offset_t offset; bool done; std::string token; + qpdf_offset_t token_start{0}; parser_state_e parser_state; std::vector> stack; std::vector ps_stack; @@ -863,6 +864,7 @@ JSONParser::getToken() action = append; switch (lex_state) { case ls_top: + token_start = offset; if (*p == '"') { lex_state = ls_string; } else if (QUtil::is_space(*p)) { @@ -1134,7 +1136,7 @@ JSONParser::handleToken() if (token.length() < 2) { throw std::logic_error("JSON string length < 2"); } - s_value = decode_string(token, offset - toO(token.length())); + s_value = decode_string(token, token_start); } std::shared_ptr item; @@ -1142,12 +1144,12 @@ JSONParser::handleToken() switch (lex_state) { case ls_begin_dict: item = std::make_shared(JSON::makeDictionary()); - item->setStart(offset - toO(token.length())); + item->setStart(token_start); break; case ls_begin_array: item = std::make_shared(JSON::makeArray()); - item->setStart(offset - toO(token.length())); + item->setStart(token_start); break; case ls_colon: @@ -1296,7 +1298,7 @@ JSONParser::handleToken() } } else if (item.get()) { if (!(item->isArray() || item->isDictionary())) { - item->setStart(offset - toO(token.length())); + item->setStart(token_start); item->setEnd(offset); } diff --git a/qpdf/qtest/qpdf/qjson-objects-not-dict.out b/qpdf/qtest/qpdf/qjson-objects-not-dict.out index 219b00e2..817ab4c4 100644 --- a/qpdf/qtest/qpdf/qjson-objects-not-dict.out +++ b/qpdf/qtest/qpdf/qjson-objects-not-dict.out @@ -1,3 +1,3 @@ -WARNING: qjson-objects-not-dict.json (offset 82): "qpdf[1]" must be a dictionary +WARNING: qjson-objects-not-dict.json (offset 81): "qpdf[1]" must be a dictionary WARNING: qjson-objects-not-dict.json: "qpdf[1].trailer" was not seen qpdf: qjson-objects-not-dict.json: errors found in JSON diff --git a/qpdf/qtest/qpdf/qjson-stream-not-dict.out b/qpdf/qtest/qpdf/qjson-stream-not-dict.out index 6a462ff6..fbd953c6 100644 --- a/qpdf/qtest/qpdf/qjson-stream-not-dict.out +++ b/qpdf/qtest/qpdf/qjson-stream-not-dict.out @@ -1,3 +1,3 @@ -WARNING: qjson-stream-not-dict.json (obj:1 0 R, offset 123): "stream" must be a dictionary +WARNING: qjson-stream-not-dict.json (obj:1 0 R, offset 122): "stream" must be a dictionary WARNING: qjson-stream-not-dict.json: "qpdf[1].trailer" was not seen qpdf: qjson-stream-not-dict.json: errors found in JSON diff --git a/qpdf/qtest/qpdf/qjson-trailer-not-dict.out b/qpdf/qtest/qpdf/qjson-trailer-not-dict.out index 3b9d482d..b8fe65e1 100644 --- a/qpdf/qtest/qpdf/qjson-trailer-not-dict.out +++ b/qpdf/qtest/qpdf/qjson-trailer-not-dict.out @@ -1,2 +1,2 @@ -WARNING: qjson-trailer-not-dict.json (trailer, offset 1269): "trailer.value" must be a dictionary +WARNING: qjson-trailer-not-dict.json (trailer, offset 1268): "trailer.value" must be a dictionary qpdf: qjson-trailer-not-dict.json: errors found in JSON