Fixing issue 1870 (#1871)

This commit is contained in:
Daniel Lemire
2022-07-19 15:17:12 -04:00
committed by GitHub
parent 5510089d45
commit 40b397a3d4
9 changed files with 22 additions and 13 deletions
-2
View File
@@ -48,6 +48,4 @@ simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uin
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
#include "simdjson/generic/stringparsing.h"
#endif // SIMDJSON_ARM64_STRINGPARSING_H
@@ -31,6 +31,4 @@ simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uin
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
#include "simdjson/generic/stringparsing.h"
#endif // SIMDJSON_FALLBACK_STRINGPARSING_H
-2
View File
@@ -43,6 +43,4 @@ simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uin
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
#include "simdjson/generic/stringparsing.h"
#endif // SIMDJSON_HASWELL_STRINGPARSING_H
-2
View File
@@ -43,6 +43,4 @@ simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uin
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
#include "simdjson/generic/stringparsing.h"
#endif // SIMDJSON_ICELAKE_STRINGPARSING_H
-2
View File
@@ -60,6 +60,4 @@ backslash_and_quote::copy_and_find(const uint8_t *src, uint8_t *dst) {
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
#include "simdjson/generic/stringparsing.h"
#endif // SIMDJSON_PPC64_STRINGPARSING_H
@@ -41,6 +41,4 @@ simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uin
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
#include "simdjson/generic/stringparsing.h"
#endif // SIMDJSON_WESTMERE_STRINGPARSING_H
+10 -1
View File
@@ -47,7 +47,12 @@ simdjson_inline bool handle_unicode_codepoint(const uint8_t **src_ptr,
// multilingual plane check
uint32_t code_point = jsoncharutils::hex_to_u32_nocheck(*src_ptr + 2);
*src_ptr += 6;
// check for low surrogate for characters outside the Basic
if (code_point >= 0xd800 && code_point < 0xdc00) {
}
// If we found a high surrogate, we must
// check for low surrogate for characters
// outside the Basic
// Multilingual Plane.
if (code_point >= 0xd800 && code_point < 0xdc00) {
if (((*src_ptr)[0] != '\\') || (*src_ptr)[1] != 'u') {
@@ -67,6 +72,10 @@ simdjson_inline bool handle_unicode_codepoint(const uint8_t **src_ptr,
code_point =
(((code_point - 0xd800) << 10) | (code_point_2 - 0xdc00)) + 0x10000;
*src_ptr += 6;
} else if (code_point >= 0xdc00 && code_point <= 0xdfff) {
// If we encounter a low surrogate (not preceded by a high surrogate)
// then we have an error.
return false;
}
size_t offset = jsoncharutils::codepoint_to_utf8(code_point, *dst_ptr);
*dst_ptr += offset;
+12
View File
@@ -52,6 +52,17 @@ namespace misc_tests {
TEST_SUCCEED();
}
bool issue1870() {
TEST_START();
ondemand::parser parser;
auto json = R"("\uDC00")"_padded;
ondemand::document doc;
ASSERT_SUCCESS(parser.iterate(json).get(doc));
std::string_view view;
ASSERT_ERROR( doc.get_string().get(view), STRING_ERROR );
TEST_SUCCEED();
}
bool issue1660() {
TEST_START();
ondemand::parser parser;
@@ -447,6 +458,7 @@ namespace misc_tests {
bool run() {
return
issue1870() &&
is_alive_root_array() &&
is_alive_root_object() &&
is_alive_array() &&