Commit cee746fc154e82df43f427b4e6112fcb50070814

Authored by m-holger
1 parent a9a06679

In JSONParser::getToken avoid copying '"' characters in strings

Showing 1 changed file with 2 additions and 8 deletions
libqpdf/JSON.cc
@@ -744,14 +744,8 @@ JSONParser::decode_string(std::string const& str, qpdf_offset_t offset) @@ -744,14 +744,8 @@ JSONParser::decode_string(std::string const& str, qpdf_offset_t offset)
744 // is called, so errors are logic errors instead of runtime 744 // is called, so errors are logic errors instead of runtime
745 // errors. 745 // errors.
746 size_t len = str.length(); 746 size_t len = str.length();
747 - if ((len < 2) || (str.at(0) != '"') || (str.at(len - 1) != '"')) {  
748 - throw std::logic_error(  
749 - "JSON Parse: decode_string called with other than \"...\"");  
750 - }  
751 char const* s = str.c_str(); 747 char const* s = str.c_str();
752 - // Move inside the quotation marks  
753 - ++s;  
754 - len -= 2; 748 +
755 // Keep track of UTF-16 surrogate pairs. 749 // Keep track of UTF-16 surrogate pairs.
756 unsigned long high_surrogate = 0; 750 unsigned long high_surrogate = 0;
757 qpdf_offset_t high_offset = 0; 751 qpdf_offset_t high_offset = 0;
@@ -878,6 +872,7 @@ JSONParser::getToken() @@ -878,6 +872,7 @@ JSONParser::getToken()
878 token_start = offset; 872 token_start = offset;
879 if (*p == '"') { 873 if (*p == '"') {
880 lex_state = ls_string; 874 lex_state = ls_string;
  875 + action = ignore;
881 } else if (QUtil::is_space(*p)) { 876 } else if (QUtil::is_space(*p)) {
882 action = ignore; 877 action = ignore;
883 } else if (*p == ',') { 878 } else if (*p == ',') {
@@ -1052,7 +1047,6 @@ JSONParser::getToken() @@ -1052,7 +1047,6 @@ JSONParser::getToken()
1052 1047
1053 case ls_string: 1048 case ls_string:
1054 if (*p == '"') { 1049 if (*p == '"') {
1055 - token += '"';  
1056 token = decode_string(token, token_start); 1050 token = decode_string(token, token_start);
1057 action = ignore; 1051 action = ignore;
1058 ready = true; 1052 ready = true;