From f11fc6e5768dd2a63fa5838213f47603b5f1fa68 Mon Sep 17 00:00:00 2001 From: jmestwa-coder Date: Wed, 29 Apr 2026 17:12:35 +0530 Subject: [PATCH] guard against overflow in AllocInst buffer growth --- re2/compile.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/re2/compile.cc b/re2/compile.cc index 95c1b32dd..a1188ec5b 100644 --- a/re2/compile.cc +++ b/re2/compile.cc @@ -251,8 +251,13 @@ int Compiler::AllocInst(int n) { int cap = inst_.size(); if (cap == 0) cap = 8; - while (ninst_ + n > cap) - cap *= 2; + while (ninst_ + n > cap) { + if (cap > max_ninst_ / 2) { + cap = max_ninst_; + } else { + cap *= 2; + } + } PODArray inst(cap); if (inst_.data() != NULL) memmove(inst.data(), inst_.data(), ninst_*sizeof inst_[0]);