From cac1d49d212d8d263a833052d2416cc84018af59 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Wed, 14 May 2025 15:41:32 +0200 Subject: [PATCH] LibWeb: Ensure we're not creating invalid ranges Our Ranges should maintain the invariant that their offsets are always within range of 0..length (inclusive) of their respective containers. Note that we cannot maintain this in AbstractRange, which is the base for StaticRange and can still have invalid offsets. --- Libraries/LibWeb/DOM/Range.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Libraries/LibWeb/DOM/Range.cpp b/Libraries/LibWeb/DOM/Range.cpp index 97c23d3a4d6..2bb9feeeec5 100644 --- a/Libraries/LibWeb/DOM/Range.cpp +++ b/Libraries/LibWeb/DOM/Range.cpp @@ -68,6 +68,9 @@ Range::Range(Document& document) Range::Range(GC::Ref start_container, WebIDL::UnsignedLong start_offset, GC::Ref end_container, WebIDL::UnsignedLong end_offset) : AbstractRange(start_container, start_offset, end_container, end_offset) { + VERIFY(start_offset <= start_container->length()); + VERIFY(end_offset <= end_container->length()); + live_ranges().set(this); }