Skip to content

Commit 1537e3f

Browse files
committed
src: provide workaround for container-overflow (issue 55584)
1 parent 4354a1d commit 1537e3f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/node_modules.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,21 @@ const BindingData::PackageConfig* BindingData::GetPackageJSON(
100100
if (ReadFileSync(&package_config.raw_json, path.data()) < 0) {
101101
return nullptr;
102102
}
103+
// In some systems, std::string is annotated to generate an
104+
// AddressSanitizer: container-overflow error when reading beyond the end of
105+
// the string even when we are still within the capacity of the string.
106+
// https://github.com/google/sanitizers/wiki/AddressSanitizerContainerOverflow
107+
// https://github.com/nodejs/node/issues/55584
108+
// The next three lines are a workaround to avoid this false positive.
109+
size_t json_length = package_config.raw_json.size();
110+
package_config.raw_json.append(simdjson::SIMDJSON_PADDING, ' ');
111+
simdjson::padded_string_view json_view(package_config.raw_json.data(), json_length, package_config.raw_json.size());
112+
// End of workaround
103113

104114
simdjson::ondemand::document document;
105115
simdjson::ondemand::object main_object;
106116
simdjson::error_code error =
107-
binding_data->json_parser.iterate(package_config.raw_json).get(document);
117+
binding_data->json_parser.iterate(json_view).get(document);
108118

109119
const auto throw_invalid_package_config = [error_context, path, realm]() {
110120
if (error_context == nullptr) {

0 commit comments

Comments
 (0)