An AS_PATH is segments; a mask is a pattern; the matcher records alignment positions in an array of 2048 + 1 stack slots. RFC 8654 extended messages let a peer deliver more path than the array can hold.

An AS_PATH is a list of segments; a mask is a pattern; the matcher records
where the pattern lands. The record is a stack array with 2048 + 1 slots —
and the sender chooses how many positions the path produces.
BGP's AS_PATH is a sequence of segments. Each segment is:
segment type 1 byte AS_SET = 1, AS_SEQUENCE = 2
segment length 1 byte number of ASNs, max 255
ASNs length × 2 or 4 bytes
An AS_SEQUENCE is an ordered path. An AS_SET is an unordered set, used for
aggregation. A path can contain multiple segments, and the total number of
ASNs is bounded only by the message size.
Historically that bound was 4096 bytes per BGP message. RFC 8654 introduced
BGP Extended Messages, raising the ceiling to 65535 bytes. That change
matters here: with 2-byte ASNs, 4096 bytes allows at most ~2048 ASNs; with
extended messages, a peer can send far more.
BIRD's filter language compiles an expression like:
bgp_path ~ [= * 64500 64501 =]
into a pattern that must be aligned against the path. The matcher walks the
path and records, for each position, where the pattern's elements line up. The
positions are stored in pm_pos, a fixed-size array of 2048 + 1 entries on
the stack.
The + 1 is a sentinel. The 2048 is the design bound: real internet paths are
tens of ASNs long, so 2048 is generous. The bug is that the code trusts that
generosity instead of enforcing it.
Two functions disagree about the bound:
parse_path() expands AS_PATH segments from a received UPDATE. It doesas_path_match() stores positions in pm_pos. It does not check theAn established peer sends a path whose expansion exceeds 2048 positions. The
matcher writes past the end of the stack array. That is the CWE-121 stack-based
buffer overflow in the advisory.
A stack buffer overflow in a routing daemon is the most dangerous class of
memory bug:
With stack canaries and non-executable stacks, a crude overflow usually aborts
the process — a remote denial of service from any peer. With an info leak and
a capable attacker, it can become control-flow hijack — code execution as the
routing daemon.
The advisory does not publish the arithmetic that turns a received path into
more than 2048 positions. Three possibilities remain open:
The advisory names parse_path() as the producer and as_path_match() as the
consumer. That is enough to know the class; it is not enough to write a
one-packet trigger without testing.

Next: Part 6 — the smaller failures and protocol edges around the matcher:
extended messages, AS_SETs, attribute lengths, and the limits that are supposed
to bound them.