diff --git a/src/codegen/assembler.cc b/src/codegen/assembler.cc index bf8a0749d2b..7534da8446c 100644 --- a/src/codegen/assembler.cc +++ b/src/codegen/assembler.cc @@ -106,7 +106,12 @@ class DefaultAssemblerBuffer : public AssemblerBuffer { int size() const override { return static_cast(buffer_.size()); } std::unique_ptr Grow(int new_size) override { - DCHECK_LT(size(), new_size); + // Guard against signed-int overflow in callers (e.g. + // Assembler::GrowBuffer's `int new_size = 2 * old_size`): if the initial + // buffer was created above kMaximalBufferSize, the doubled size wraps + // negative and silently produces a kMinimalBufferSize (128-byte) buffer, + // which the caller then MemMoves ~1 GiB of code into. + CHECK_LT(size(), new_size); return std::make_unique(new_size); }