Skip to content

Commit 05f9ca4

Browse files
pthierV8 LUCI CQ
authored andcommitted
[regexp] Fix potential overflow on 32-bit builds
In RegExpMatchGlobalAtom_OneCharPattern, if subject is allocated at a high address, it is possible that `block + stride * max_count` overflows on 32-bit builds on a 64-bit platform. Fix this by comparing `stride * max_count` against the remaining length. Fixed: 449767585 Change-Id: I6a7be4064f53a2282b98c6a1f342e1b646d29b71 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7021933 Auto-Submit: Patrick Thier <[email protected]> Reviewed-by: Jakob Linke <[email protected]> Commit-Queue: Jakob Linke <[email protected]> Cr-Commit-Position: refs/heads/main@{#103009}
1 parent ac57598 commit 05f9ca4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/runtime/runtime-regexp.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,7 +2200,7 @@ inline void RegExpMatchGlobalAtom_OneCharPattern(
22002200
// the maximum number of matches we can count in the vector before it
22012201
// overflows.
22022202
int max_count = std::numeric_limits<SChar>::max();
2203-
while (block + stride * max_count <= end) {
2203+
while (stride * max_count <= static_cast<size_t>(end - block)) {
22042204
for (int i = 0; i < max_count; i++, block += stride) {
22052205
const auto input = hw::LoadU(tag, block);
22062206
// TODO(floitsch): use an operator for the comparison when it is available
@@ -2224,7 +2224,7 @@ inline void RegExpMatchGlobalAtom_OneCharPattern(
22242224
// For blocks shorter than stride * max_count, lanes in submatches can't
22252225
// overflow.
22262226
DCHECK_LT(end - block, stride * max_count);
2227-
for (; block + stride <= end; block += stride) {
2227+
for (; stride <= static_cast<size_t>(end - block); block += stride) {
22282228
const auto input = hw::LoadU(tag, block);
22292229
// TODO(floitsch): use an operator for the comparison when it is available
22302230
// on RISC-V.

0 commit comments

Comments
 (0)