Commit cee746fc154e82df43f427b4e6112fcb50070814
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 | 744 | // is called, so errors are logic errors instead of runtime |
| 745 | 745 | // errors. |
| 746 | 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 | 747 | char const* s = str.c_str(); |
| 752 | - // Move inside the quotation marks | |
| 753 | - ++s; | |
| 754 | - len -= 2; | |
| 748 | + | |
| 755 | 749 | // Keep track of UTF-16 surrogate pairs. |
| 756 | 750 | unsigned long high_surrogate = 0; |
| 757 | 751 | qpdf_offset_t high_offset = 0; |
| ... | ... | @@ -878,6 +872,7 @@ JSONParser::getToken() |
| 878 | 872 | token_start = offset; |
| 879 | 873 | if (*p == '"') { |
| 880 | 874 | lex_state = ls_string; |
| 875 | + action = ignore; | |
| 881 | 876 | } else if (QUtil::is_space(*p)) { |
| 882 | 877 | action = ignore; |
| 883 | 878 | } else if (*p == ',') { |
| ... | ... | @@ -1052,7 +1047,6 @@ JSONParser::getToken() |
| 1052 | 1047 | |
| 1053 | 1048 | case ls_string: |
| 1054 | 1049 | if (*p == '"') { |
| 1055 | - token += '"'; | |
| 1056 | 1050 | token = decode_string(token, token_start); |
| 1057 | 1051 | action = ignore; |
| 1058 | 1052 | ready = true; | ... | ... |