avutil/hwcontext_vulkan: copy only the bytes of the visible rows #25249

Merged
Lynne merged 1 commit from prasanna8585/FFmpeg:hwcontext-vulkan-visible-rows into master 2026-10-20 09:31:13 +00:00
Contributor

copy_buffer_data() copied FFABS(linesize) bytes per row between the software frame and the staging buffer. The last row of a plane does not have to extend to the full linesize, so this reads past the end of the software frame on upload and writes past it on download. Same issue as fixed for hwcontext_cuda in f07f02abb8.

The staging path is always used for frames with a negative linesize, and by default for multi-plane formats (NV12, P010, ...) on the NVIDIA proprietary driver, where host image copies are disabled and avoid_host_import is on.

Reproduced through the API (av_hwframe_transfer_data()) with ASan on Mesa lavapipe, using a GRAY8 100x16 frame with linesize 128 whose last row holds only the visible 100 bytes:

  • upload: heap-buffer-overflow READ of size 128, 0 bytes after the 2020-byte frame buffer (copy_buffer_data)
  • download: heap-buffer-overflow WRITE of size 128, 0 bytes after the 2020-byte frame buffer (copy_buffer_data)

With the patch both are clean, fully padded frames are unaffected, and an upload/download round trip through the staging path reproduces all visible bytes.

`copy_buffer_data()` copied `FFABS(linesize)` bytes per row between the software frame and the staging buffer. The last row of a plane does not have to extend to the full linesize, so this reads past the end of the software frame on upload and writes past it on download. Same issue as fixed for hwcontext_cuda in f07f02abb864. The staging path is always used for frames with a negative linesize, and by default for multi-plane formats (NV12, P010, ...) on the NVIDIA proprietary driver, where host image copies are disabled and `avoid_host_import` is on. Reproduced through the API (`av_hwframe_transfer_data()`) with ASan on Mesa lavapipe, using a GRAY8 100x16 frame with linesize 128 whose last row holds only the visible 100 bytes: - upload: heap-buffer-overflow READ of size 128, 0 bytes after the 2020-byte frame buffer (copy_buffer_data) - download: heap-buffer-overflow WRITE of size 128, 0 bytes after the 2020-byte frame buffer (copy_buffer_data) With the patch both are clean, fully padded frames are unaffected, and an upload/download round trip through the staging path reproduces all visible bytes.
avutil/hwcontext_vulkan: copy only the bytes of the visible rows
All checks were successful
Backport / PR (pull_request_target) Has been skipped
Lint / Pre-Commit (pull_request) Successful in 30s
Test / Fate (linux-loongarch64, static, 64 bit) (pull_request) Successful in 6m10s
Test / Fate (linux-aarch64, static, 64 bit) (pull_request) Successful in 7m47s
Test / Fate (Full, Linux, aarch64) (pull_request) Successful in 10m5s
Test / Fate (linux-amd64, static, 32 bit) (pull_request) Successful in 10m32s
Test / Fate (linux-amd64, shared, 64 bit) (pull_request) Successful in 13m12s
Test / Fate (Qemu, Linux, mips64) (pull_request) Successful in 21m46s
Test / Fate (Qemu, Linux, ppc64) (pull_request) Successful in 24m41s
Test / Fate (Qemu, Linux, riscv64) (pull_request) Successful in 28m11s
Test / Fate (Full, Wine, win64) (pull_request) Successful in 32m27s
Autolabel / Labeler (pull_request_target) Successful in 17s
Lint / Pre-Commit (push) Successful in 35s
Test / Fate (linux-loongarch64, static, 64 bit) (push) Successful in 6m10s
Test / Fate (Full, Linux, aarch64) (push) Successful in 9m45s
Test / Fate (linux-aarch64, static, 64 bit) (push) Successful in 12m41s
Test / Fate (Qemu, Linux, mips64) (push) Successful in 13m17s
Test / Fate (linux-amd64, static, 32 bit) (push) Successful in 16m3s
Test / Fate (linux-amd64, shared, 64 bit) (push) Successful in 17m43s
Test / Fate (Qemu, Linux, ppc64) (push) Successful in 24m22s
Test / Fate (Qemu, Linux, riscv64) (push) Successful in 28m3s
Test / Fate (Full, Wine, win64) (push) Successful in 31m46s
fdd4e83ea0
copy_buffer_data() copied FFABS(linesize) bytes per row between the
software frame and the staging buffer. The last row of a plane does not
have to extend to the full linesize, so this read past the end of the
software frame on upload and wrote past it on download.

The staging path is always taken for frames with a negative linesize,
and by default for multi-plane formats on the NVIDIA proprietary driver,
where host image copies are disabled and host memory import is avoided.

Same issue as fixed for hwcontext_cuda in f07f02abb8.

Out of array read and write replicated through the API with ASAN.
Lynne approved these changes 2026-10-20 08:56:08 +00:00
Lynne scheduled this pull request to auto merge when all checks succeed 2026-10-20 08:56:25 +00:00
Lynne merged commit fdd4e83ea0 into master 2026-10-20 09:31:13 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
FFmpeg/FFmpeg!25249
No description provided.