You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
EncodedS2ShapeIndex: OOM (16 GiB alloc) from unchecked num_edges/num_clipped #677
OOM (16 GiB allocation) from unchecked size fields in S2ShapeIndexCell::Decode
A 117-byte malformed input causes S2ShapeIndexCell::Decode() to attempt a single operator new(17179869180) (~16 GiB), crashing with OOM.
Root cause
Three values decoded from the untrusted header are used for allocation without bounds
checks:
Single-shape path — int num_edges = header >> 3; where header is uint64_t.
A large header makes header >> 3 overflow int (→ negative), which sign-extends to 0xFFFFFFFF when passed to S2ClippedShape::Init, which does edges_ = new int32_t[0xFFFFFFFF] = 17179869180 bytes.
Multi-shape path — num_clipped = header >> 3 is unbounded, so add_shapes() allocates
memory proportional to an attacker-controlled count.
Related framing: #686 documents the trusted byte stream assumption on EncodedS2ShapeIndex::Init — that a true return does not mean the encoding is sound, because cells are decoded lazily and a malformed one is not reached until later.
The behaviour reported here is unchanged; the note only states the contract a caller is operating under when it hands the decoder an encoding that does not satisfy it. Filing it as documentation rather than a fix follows jmr's reading on #674.
Activity
test: add regression tests for malformed encoded indexes (google#674/g…
sushant-me commentedon Oct 5, 2026
Related framing: #686 documents the trusted byte stream assumption on
EncodedS2ShapeIndex::Init— that atruereturn does not mean the encoding is sound, because cells are decoded lazily and a malformed one is not reached until later.The behaviour reported here is unchanged; the note only states the contract a caller is operating under when it hands the decoder an encoding that does not satisfy it. Filing it as documentation rather than a fix follows jmr's reading on #674.