From 1537e3f2779099f9b5aa355dd9179029ce95a93d Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Tue, 29 Oct 2024 12:28:47 -0400 Subject: [PATCH 1/2] src: provide workaround for container-overflow (issue 55584) --- src/node_modules.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/node_modules.cc b/src/node_modules.cc index dfd115a9eccc6b..3f74efc364feee 100644 --- a/src/node_modules.cc +++ b/src/node_modules.cc @@ -100,11 +100,21 @@ const BindingData::PackageConfig* BindingData::GetPackageJSON( if (ReadFileSync(&package_config.raw_json, path.data()) < 0) { return nullptr; } + // In some systems, std::string is annotated to generate an + // AddressSanitizer: container-overflow error when reading beyond the end of + // the string even when we are still within the capacity of the string. + // https://github.com/google/sanitizers/wiki/AddressSanitizerContainerOverflow + // https://github.com/nodejs/node/issues/55584 + // The next three lines are a workaround to avoid this false positive. + size_t json_length = package_config.raw_json.size(); + package_config.raw_json.append(simdjson::SIMDJSON_PADDING, ' '); + simdjson::padded_string_view json_view(package_config.raw_json.data(), json_length, package_config.raw_json.size()); + // End of workaround simdjson::ondemand::document document; simdjson::ondemand::object main_object; simdjson::error_code error = - binding_data->json_parser.iterate(package_config.raw_json).get(document); + binding_data->json_parser.iterate(json_view).get(document); const auto throw_invalid_package_config = [error_context, path, realm]() { if (error_context == nullptr) { From f80d4653b26b08bc41bc3de1486741154f6616f2 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Tue, 29 Oct 2024 12:30:11 -0400 Subject: [PATCH 2/2] lint --- src/node_modules.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/node_modules.cc b/src/node_modules.cc index 3f74efc364feee..16a9f923148835 100644 --- a/src/node_modules.cc +++ b/src/node_modules.cc @@ -105,10 +105,12 @@ const BindingData::PackageConfig* BindingData::GetPackageJSON( // the string even when we are still within the capacity of the string. // https://github.com/google/sanitizers/wiki/AddressSanitizerContainerOverflow // https://github.com/nodejs/node/issues/55584 - // The next three lines are a workaround to avoid this false positive. + // The next lines are a workaround to avoid this false positive. size_t json_length = package_config.raw_json.size(); package_config.raw_json.append(simdjson::SIMDJSON_PADDING, ' '); - simdjson::padded_string_view json_view(package_config.raw_json.data(), json_length, package_config.raw_json.size()); + simdjson::padded_string_view json_view(package_config.raw_json.data(), + json_length, + package_config.raw_json.size()); // End of workaround simdjson::ondemand::document document;