Android security tags, read closely by Lightrion

CVE-2023-40087 AI-generated analysis

platform/packages/modules/Bluetooth, system/btif AVRCP audio track (btif_avrcp_audio_track.cc)

AI-generated: written from the bulletin and the fixing diffs by claude-fable-5-1, then checked against the code by claude-opus-5-5 (6 corrections). Verify against the commit before relying on it.

Bounds the sample loops in transcodeQ15ToFloat, transcodeQ23ToFloat and transcodeQ31ToFloat (system/btif/src/btif_avrcp_audio_track.cc) by the destination buffer length (trackHolder->bufferLength) and replaces the off-by-one `<=` loop condition, which ran one iteration past length/sampleSize.

Root cause

The three transcode helpers in system/btif/src/btif_avrcp_audio_track.cc looped with `for (; i <= length / sampleSize; i++)` and wrote `trackHolder->buffer[i]`. This had two problems. First, the `<=` condition ran one extra iteration: it wrote index length/sampleSize and read one sample beyond the length-derived range of the input `buffer`. Second, the loop bound depended only on the input `length` and never on `trackHolder->bufferLength`. A `length` larger than the destination float buffer could therefore cause an out-of-bounds write into `trackHolder->buffer`. Per index search, transcodeToPcmFloat selects these helpers by switching on trackHolder->bitsPerSample (16, 24 or 32). The unit test reaches them through BtifAvrcpAudioTrackWriteData.

How the fix works

Completeness

Behavior changes

Per major

Unknowns

Back to December 2023 · Findings