From 91f55e4dec9c3382815041a5f0e376bebafe3df0 Mon Sep 17 00:00:00 2001 From: Austin Orion Date: Fri, 7 Jan 2022 15:05:07 -0800 Subject: [PATCH] Avoid container-overflow in WgcCaptureSession::GetFrame ASAN is throwing a container-overflow because we are accessing a region in the vector that is valid but does not have an element. We can avoid this by using resize instead of reserve. See the documentation for container-overflow for more details: https://github.com/google/sanitizers/wiki/AddressSanitizerContainerOverflow#:~:text=One%20kind%20of%20bugs%20that%20AddressSanitizer%20can%20find,outside%20of%20the%20current%20container%20bounds.%20Simplest%20example%3A Bug: webrtc:13541 Change-Id: Id11def90ef8c2cfec9c20f38384547ce6c37b980 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/244861 Reviewed-by: Alexander Cooper Commit-Queue: Austin Orion Cr-Commit-Position: refs/heads/main@{#35654} --- modules/desktop_capture/win/wgc_capture_session.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/desktop_capture/win/wgc_capture_session.cc b/modules/desktop_capture/win/wgc_capture_session.cc index 22dbf90204..09c336fdc5 100644 --- a/modules/desktop_capture/win/wgc_capture_session.cc +++ b/modules/desktop_capture/win/wgc_capture_session.cc @@ -290,7 +290,7 @@ HRESULT WgcCaptureSession::GetFrame( // unmap our texture. uint8_t* src_data = static_cast(map_info.pData); std::vector image_data; - image_data.reserve(image_height * row_data_length); + image_data.resize(image_height * row_data_length); uint8_t* image_data_ptr = image_data.data(); for (int i = 0; i < image_height; i++) { memcpy(image_data_ptr, src_data, row_data_length);