Why asking for part of a 5-byte attribute can read the whole heap (animated)
Finding F1 from the bluetooth scan. Two small numbers, one missing check, and a "please send me a slice" request makes the phone read heap it should never touch. Press Play.
The strip is a 400-byte SDP work buffer. Cells 0..4 are the attribute
(type byte + 4 data bytes in the repro). The thick mark is where the buffer ends.
Beyond it sits other device memory. Attacker asks for the attribute "starting at byte 300";
the phone does 5 - 300. C promotes both operands to signed int,
so that is -295, not 65538, and a negative number is always "smaller than the
budget", so memcpy runs with a huge length from offset 300 — a heap over-read.
The real tree guards the offset in its SDP server callers; the bug is that the helper itself
owns the check, so any future caller that forgets it reintroduces this.