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
OOM (2.4 GiB alloc) via unchecked num_edges in single-shape S2ShapeIndexCell::Decode #679
In the single-shape branch (src/s2/s2shape_index.cc), after the int-overflow
guard added in #677, num_edges = header >> 3 is bounded only against int32_t::max() — not against the remaining input bytes. A header value that
yields a large-but-positive num_edges (e.g. 603,979,775) passes the check and S2ClippedShape::Init(0, num_edges) allocates num_edges * 4 ≈ 2.4 GiB before DecodeEdges() reads the (absent) edge data.
This is the single-shape counterpart of the multi-shape gap fixed in #677: the
multi-shape path was bounded with if (num_edges > decoder->avail()) return false;,
but the single-shape path was not.
Reproduction
28-byte input (base64):
CAgEAP7/6ggLCAgICHgICP////8R/7L3AP//6g==
Decode to a file and pass to a harness that calls MutableS2ShapeIndex::Init
(or EncodedS2ShapeIndex::Init) with a LazyDecodeShapeFactory; the Init() succeeds and the allocation is observed under ASan/libFuzzer
(-rss_limit_mb default).
Impact
Denial of service via unbounded allocation from a tiny untrusted input (memory
exhaustion), same class as #677.
Related to #677 (the int-overflow OOM); this is the large-but-positive case the #677 fix did not cover.
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
Bound num_edges against remaining input in single-shape cell decode
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.