| Index: src/runtime.cc
|
| diff --git a/src/runtime.cc b/src/runtime.cc
|
| index cf143127acade800d3cf13e9354bc581f1ba2ce0..89f50255789ac1f9d80a3d521aa2fa83e8554d3f 100644
|
| --- a/src/runtime.cc
|
| +++ b/src/runtime.cc
|
| @@ -2985,7 +2985,15 @@ MUST_USE_RESULT static MaybeObject* StringReplaceAtomRegExpWithString(
|
| int matches = indices.length();
|
| if (matches == 0) return *subject;
|
|
|
| - int result_len = (replacement_len - pattern_len) * matches + subject_len;
|
| + // Detect integer overflow.
|
| + int64_t result_len_64 =
|
| + (static_cast<int64_t>(replacement_len) -
|
| + static_cast<int64_t>(pattern_len)) *
|
| + static_cast<int64_t>(matches) +
|
| + static_cast<int64_t>(subject_len);
|
| + if (result_len_64 > INT_MAX) return Failure::OutOfMemoryException();
|
| + int result_len = static_cast<int>(result_len_64);
|
| +
|
| int subject_pos = 0;
|
| int result_pos = 0;
|
|
|
|
|