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

Side by Side Diff: webrtc/common_types.cc

Issue 2915913003: Prevent memory corruption by StreamId::Set (Closed)
Patch Set: CR response Created 3 years, 6 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
11 #include "webrtc/common_types.h" 11 #include "webrtc/common_types.h"
12 12
13 #include <string.h> 13 #include <string.h>
14 #include <limits> 14 #include <limits>
15 #include <type_traits> 15 #include <type_traits>
16 16
17 #include "webrtc/base/checks.h" 17 #include "webrtc/base/checks.h"
18 #include "webrtc/base/stringutils.h" 18 #include "webrtc/base/stringutils.h"
19 19
20 namespace webrtc { 20 namespace webrtc {
21 21
22 StreamDataCounters::StreamDataCounters() : first_packet_time_ms(-1) {} 22 StreamDataCounters::StreamDataCounters() : first_packet_time_ms(-1) {}
23 23
24 constexpr size_t StreamId::kMaxSize; 24 constexpr size_t StreamId::kMaxSize;
25 25
26 void StreamId::Set(const char* data, size_t size) { 26 void StreamId::Set(const char* data, size_t size) {
27 // If |data| contains \0, the stream id size might become less than |size|. 27 // If |data| contains \0, the stream id size might become less than |size|.
28 RTC_DCHECK_LE(size, kMaxSize); 28 RTC_CHECK_LE(size, kMaxSize);
29 memcpy(value_, data, size); 29 memcpy(value_, data, size);
30 if (size < kMaxSize) 30 if (size < kMaxSize)
31 value_[size] = 0; 31 value_[size] = 0;
32 } 32 }
33 33
34 // StreamId is used as member of RTPHeader that is sometimes copied with memcpy 34 // StreamId is used as member of RTPHeader that is sometimes copied with memcpy
35 // and thus assume trivial destructibility. 35 // and thus assume trivial destructibility.
36 static_assert(std::is_trivially_destructible<StreamId>::value, ""); 36 static_assert(std::is_trivially_destructible<StreamId>::value, "");
37 37
38 RTPHeaderExtension::RTPHeaderExtension() 38 RTPHeaderExtension::RTPHeaderExtension()
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 // Get the sum of all the temporal layer for a specific spatial layer. 195 // Get the sum of all the temporal layer for a specific spatial layer.
196 uint32_t BitrateAllocation::GetSpatialLayerSum(size_t spatial_index) const { 196 uint32_t BitrateAllocation::GetSpatialLayerSum(size_t spatial_index) const {
197 RTC_CHECK_LT(spatial_index, kMaxSpatialLayers); 197 RTC_CHECK_LT(spatial_index, kMaxSpatialLayers);
198 uint32_t sum = 0; 198 uint32_t sum = 0;
199 for (int i = 0; i < kMaxTemporalStreams; ++i) 199 for (int i = 0; i < kMaxTemporalStreams; ++i)
200 sum += bitrates_[spatial_index][i]; 200 sum += bitrates_[spatial_index][i];
201 return sum; 201 return sum;
202 } 202 }
203 203
204 } // namespace webrtc 204 } // 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