parser.load(string_view) does not respect view length when opening files (#2659)

This commit is contained in:
jmestwa-coder
2026-04-04 00:55:03 +05:30
committed by GitHub
parent 769364abb2
commit 542cd7af71
2 changed files with 17 additions and 1 deletions
+2 -1
View File
@@ -36,10 +36,11 @@ inline bool parser::dump_raw_tape(std::ostream &os) const noexcept {
}
inline simdjson_result<size_t> parser::read_file(std::string_view path) noexcept {
const std::string path_copy(path);
// Open the file
SIMDJSON_PUSH_DISABLE_WARNINGS
SIMDJSON_DISABLE_DEPRECATED_WARNING // Disable CRT_SECURE warning on MSVC: manually verified this is safe
std::FILE *fp = std::fopen(path.data(), "rb");
std::FILE *fp = std::fopen(path_copy.c_str(), "rb");
SIMDJSON_POP_DISABLE_WARNINGS
if (fp == nullptr) {
+15
View File
@@ -114,6 +114,20 @@ namespace parser_load {
TEST_SUCCEED();
}
bool parser_load_string_view_subpath() {
TEST_START();
const std::string valid_path(TWITTER_JSON);
const std::string backing = valid_path + ".extra";
const std::string_view view(backing.data(), valid_path.size());
uint64_t count_from_string = 0;
uint64_t count_from_view = 0;
dom::parser parser;
ASSERT_SUCCESS(parser.load(valid_path)["search_metadata"]["count"].get(count_from_string));
ASSERT_SUCCESS(parser.load(view)["search_metadata"]["count"].get(count_from_view));
ASSERT_EQUAL(count_from_view, count_from_string);
TEST_SUCCEED();
}
bool parser_load_chain() {
TEST_START();
dom::parser parser;
@@ -136,6 +150,7 @@ namespace parser_load {
&& parser_load_nonexistent()
&& parser_load_many_nonexistent()
&& padded_string_load_nonexistent()
&& parser_load_string_view_subpath()
&& parser_load_chain()
&& parser_load_many_chain()
&& parser_parse_many_documents_error_in_the_middle()