When a Bluetooth peer tells you how big its response will be and you allocate that up front, a lying peer can ask for gigabytes and crash your app.
What goes wrong
A message from the connected peer carries two numbers: how large the whole response will be and how big each chunk is. Both go straight into the object that allocates buffers to reassemble the transfer. Nothing checks them against a sane ceiling first.
A real device sends modest numbers. A malicious one advertises an enormous response size, and the allocator dutifully tries to reserve room for it during setup, before a single byte of actual data arrives. The app spikes memory or falls over. The peer never had to send a large payload, only claim that it would.
The pattern
function onMessage(msg) {
const size = msg.responseSize // from the peer
const chunk = msg.maxDataBytes // from the peer
const buffer = new TransferBuffer(size, chunk) // allocates up front
return buffer
}function onMessage(msg) {
const size = msg.responseSize
const chunk = msg.maxDataBytes
if (size > MAX_RESPONSE || chunk <= 0 || chunk > MAX_CHUNK)
throw new Error('declared size out of range')
const buffer = new TransferBuffer(size, chunk)
return buffer
}Grounding and reachability were confirmed. The exploit-path gate would not conclude without the calling code, so the finding was held and an evidence request was raised instead of being reported as fact.
Why it matters to you
Anything that pairs over Bluetooth trusts a device the user may not control and you certainly do not. Treat a wireless peer the way you treat a network client: hostile until proven otherwise. A crash here is a denial of service on a phone or an access device, triggered by a peer in radio range with no authentication.
Numbers that describe how much to allocate are the most dangerous fields a peer can send. Clamp them to limits you set before you hand them to any allocator.
Check your own code
- Validate every size and count from a wireless peer against a hard maximum.
- Reject zero or negative chunk sizes before allocating.
- Allocate incrementally as data arrives rather than reserving the declared total.
- Fuzz the pairing path with absurd declared sizes.