Skip to content

Bound AudioFrame.planes by the number of planes - #2502

Merged
WyattBlue merged 4 commits into
PyAV-Org:masterfrom
ChandraChaan:fix/audio-planes-bound
Nov 2, 2026
Merged

WyattBlue merged 4 commits into
PyAV-Org:masterfrom
ChandraChaan:fix/audio-planes-bound

Conversation

@ChandraChaan

Copy link
Copy Markdown
Contributor

AudioFrame.planes counted planes by walking extended_data until it hit a NULL pointer, but extended_data is not NULL-terminated.

For planar audio with 8 channels (e.g. fltp / 7.1), FFmpeg points extended_data at the frame's own data[8] array, which is followed by linesize[8]. The loop therefore read linesize[0] as a ninth plane pointer, counted 9 planes, and AudioPlane raised plane index 8 out of range for 8 planes. So .planes, to_ndarray() and from_ndarray() all fail for 7.1 planar audio. With more than 8 channels the loop read past the end of the heap-allocated extended_data array.

The loop now stops at the number of planes (nb_channels for planar formats, 1 for packed), the same way VideoFrame.planes already caps its count. The NULL check stays, so a frame without buffers still has no planes.

Added test_manual_fltp_7_1_constructor. I ran the smoke workflow on my fork with the test alone and with the fix:

The RISC-V job never got a runner on my fork, so it didn't run.

extended_data is not NULL-terminated. With 8 planar channels it points at
the frame's data[8] array, so the loop read linesize[0] as a ninth plane
pointer and AudioPlane raised "plane index 8 out of range for 8 planes":
.planes, to_ndarray() and from_ndarray() failed for 7.1 planar audio.
With more than 8 channels the loop read past the end of the heap array.

Stop at the number of planes, as VideoFrame.planes already does.
@WyattBlue
WyattBlue merged commit abd7340 into PyAV-Org:master Nov 2, 2026
7 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants