Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: webrtc/modules/audio_processing/aec/aec_core.cc

Issue 2980723002: Avoid buffer over-read in AEC2 by zeroing memory instead of copying. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 void BlockBuffer::Insert(const float block[PART_LEN]) { 199 void BlockBuffer::Insert(const float block[PART_LEN]) {
200 WebRtc_WriteBuffer(buffer_, block, 1); 200 WebRtc_WriteBuffer(buffer_, block, 1);
201 } 201 }
202 202
203 void BlockBuffer::ExtractExtendedBlock(float extended_block[PART_LEN2]) { 203 void BlockBuffer::ExtractExtendedBlock(float extended_block[PART_LEN2]) {
204 float* block_ptr = NULL; 204 float* block_ptr = NULL;
205 RTC_DCHECK_LT(0, AvaliableSpace()); 205 RTC_DCHECK_LT(0, AvaliableSpace());
206 206
207 // Extract the previous block. 207 // Extract the previous block.
208 WebRtc_MoveReadPtr(buffer_, -1); 208 WebRtc_MoveReadPtr(buffer_, -1);
209 WebRtc_ReadBuffer(buffer_, reinterpret_cast<void**>(&block_ptr), 209 size_t read_elements = WebRtc_ReadBuffer(
210 &extended_block[0], 1); 210 buffer_, reinterpret_cast<void**>(&block_ptr), &extended_block[0], 1);
211 if (block_ptr != &extended_block[0]) { 211 if (read_elements == 0u) {
212 std::fill_n(&extended_block[0], PART_LEN, 0.0f);
213 } else if (block_ptr != &extended_block[0]) {
212 memcpy(&extended_block[0], block_ptr, PART_LEN * sizeof(float)); 214 memcpy(&extended_block[0], block_ptr, PART_LEN * sizeof(float));
213 } 215 }
214 216
215 // Extract the current block. 217 // Extract the current block.
216 WebRtc_ReadBuffer(buffer_, reinterpret_cast<void**>(&block_ptr), 218 read_elements =
217 &extended_block[PART_LEN], 1); 219 WebRtc_ReadBuffer(buffer_, reinterpret_cast<void**>(&block_ptr),
218 if (block_ptr != &extended_block[PART_LEN]) { 220 &extended_block[PART_LEN], 1);
221 if (read_elements == 0u) {
222 std::fill_n(&extended_block[PART_LEN], PART_LEN, 0.0f);
223 } else if (block_ptr != &extended_block[PART_LEN]) {
219 memcpy(&extended_block[PART_LEN], block_ptr, PART_LEN * sizeof(float)); 224 memcpy(&extended_block[PART_LEN], block_ptr, PART_LEN * sizeof(float));
220 } 225 }
221 } 226 }
222 227
223 int BlockBuffer::AdjustSize(int buffer_size_decrease) { 228 int BlockBuffer::AdjustSize(int buffer_size_decrease) {
224 return WebRtc_MoveReadPtr(buffer_, buffer_size_decrease); 229 return WebRtc_MoveReadPtr(buffer_, buffer_size_decrease);
225 } 230 }
226 231
227 size_t BlockBuffer::Size() { 232 size_t BlockBuffer::Size() {
228 return static_cast<int>(WebRtc_available_read(buffer_)); 233 return static_cast<int>(WebRtc_available_read(buffer_));
(...skipping 1809 matching lines...) Expand 10 before | Expand all | Expand 10 after
2038 2043
2039 int WebRtcAec_system_delay(AecCore* self) { 2044 int WebRtcAec_system_delay(AecCore* self) {
2040 return self->system_delay; 2045 return self->system_delay;
2041 } 2046 }
2042 2047
2043 void WebRtcAec_SetSystemDelay(AecCore* self, int delay) { 2048 void WebRtcAec_SetSystemDelay(AecCore* self, int delay) {
2044 RTC_DCHECK_GE(delay, 0); 2049 RTC_DCHECK_GE(delay, 0);
2045 self->system_delay = delay; 2050 self->system_delay = delay;
2046 } 2051 }
2047 } // namespace webrtc 2052 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698