Fix double mapoffset application in PipeWire video capture mmap() with mapoffset as the file offset already returns a pointer to the data at that offset, so passing it again to SPA_MEMBER was reading mapoffset bytes past the mapped region. Also queue the buffer back to PipeWire before returning on mmap failure to avoid leaking it. Bug: chromium:505647674 Change-Id: Iba306e80b008e71b420f15e74db67b1496ddc403 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/466361 Reviewed-by: Per Kjellander <perkj@webrtc.org> Commit-Queue: Jan Grulich <grulja@gmail.com> Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Cr-Commit-Position: refs/heads/main@{#47562}
diff --git a/modules/video_capture/linux/video_capture_pipewire.cc b/modules/video_capture/linux/video_capture_pipewire.cc index ca35498..c83867e 100644 --- a/modules/video_capture/linux/video_capture_pipewire.cc +++ b/modules/video_capture/linux/video_capture_pipewire.cc
@@ -490,12 +490,12 @@ if (!frame) { RTC_LOG(LS_ERROR) << "Failed to mmap the memory: " << std::strerror(errno); + pw_stream_queue_buffer(stream_, buffer); return; } - IncomingFrame( - SPA_MEMBER(frame.get(), spaBuffer->datas[0].mapoffset, uint8_t), - spaBuffer->datas[0].chunk->size, configured_capability_); + IncomingFrame(frame.get(), spaBuffer->datas[0].chunk->size, + configured_capability_); } else { // SPA_DATA_MemPtr IncomingFrame(static_cast<uint8_t*>(spaBuffer->datas[0].data), spaBuffer->datas[0].chunk->size, configured_capability_);