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

Side by Side Diff: media/cdm/cenc_utils_unittest.cc

Issue 1559013002: Fix possible loss of data warnings in media_unittests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/cdm/cenc_utils.h" 5 #include "media/cdm/cenc_utils.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 box.push_back(0); 152 box.push_back(0);
153 return box; 153 return box;
154 } 154 }
155 155
156 void AppendData(std::vector<uint8_t>& pssh_box, 156 void AppendData(std::vector<uint8_t>& pssh_box,
157 const std::vector<uint8_t>& data) { 157 const std::vector<uint8_t>& data) {
158 // This assumes that |pssh_box| has been created using the routines above, 158 // This assumes that |pssh_box| has been created using the routines above,
159 // and simply appends the data to the end of it. It updates the box size 159 // and simply appends the data to the end of it. It updates the box size
160 // and sets the data size. 160 // and sets the data size.
161 DCHECK(data.size() < 100); 161 DCHECK(data.size() < 100);
162 pssh_box[3] += data.size(); 162 pssh_box[3] += static_cast<uint8_t>(data.size());
163 pssh_box.pop_back(); 163 pssh_box.pop_back();
164 pssh_box.push_back(data.size()); 164 pssh_box.push_back(static_cast<uint8_t>(data.size()));
165 pssh_box.insert(pssh_box.end(), data.begin(), data.end()); 165 pssh_box.insert(pssh_box.end(), data.begin(), data.end());
166 } 166 }
167 167
168 const std::vector<uint8_t>& Key1() { return key1_; } 168 const std::vector<uint8_t>& Key1() { return key1_; }
169 const std::vector<uint8_t>& Key2() { return key2_; } 169 const std::vector<uint8_t>& Key2() { return key2_; }
170 const std::vector<uint8_t>& Key3() { return key3_; } 170 const std::vector<uint8_t>& Key3() { return key3_; }
171 const std::vector<uint8_t>& Key4() { return key4_; } 171 const std::vector<uint8_t>& Key4() { return key4_; }
172 const std::vector<uint8_t>& CommonSystemSystemId() { 172 const std::vector<uint8_t>& CommonSystemSystemId() {
173 return common_system_system_id_; 173 return common_system_system_id_;
174 } 174 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 } 277 }
278 } 278 }
279 279
280 TEST_F(CencUtilsTest, PsshBoxLargerThanSize) { 280 TEST_F(CencUtilsTest, PsshBoxLargerThanSize) {
281 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); 281 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
282 KeyIdList key_ids; 282 KeyIdList key_ids;
283 283
284 // Add 20 additional bytes to |box|. 284 // Add 20 additional bytes to |box|.
285 size_t original_size = box.size(); 285 size_t original_size = box.size();
286 for (size_t i = 0; i < 20; ++i) 286 for (size_t i = 0; i < 20; ++i)
287 box.push_back(i); 287 box.push_back(static_cast<uint8_t>(i));
288 288
289 // Tries every size greater than |original_size|. 289 // Tries every size greater than |original_size|.
290 for (size_t i = original_size + 1; i < box.size(); ++i) { 290 for (size_t i = original_size + 1; i < box.size(); ++i) {
291 // Modify size of box passed to be less than current size. 291 // Modify size of box passed to be less than current size.
292 std::vector<uint8_t> truncated(&box[0], &box[0] + i); 292 std::vector<uint8_t> truncated(&box[0], &box[0] + i);
293 EXPECT_FALSE(ValidatePsshInput(truncated)) << "Failed for length " << i; 293 EXPECT_FALSE(ValidatePsshInput(truncated)) << "Failed for length " << i;
294 EXPECT_FALSE(GetKeyIdsForCommonSystemId(truncated, &key_ids)); 294 EXPECT_FALSE(GetKeyIdsForCommonSystemId(truncated, &key_ids));
295 } 295 }
296 } 296 }
297 297
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 EXPECT_FALSE(ValidatePsshInput(boxes)); 547 EXPECT_FALSE(ValidatePsshInput(boxes));
548 548
549 // Repeat with |non_pssh_box| first. 549 // Repeat with |non_pssh_box| first.
550 boxes.clear(); 550 boxes.clear();
551 boxes.insert(boxes.end(), non_pssh_box.begin(), non_pssh_box.end()); 551 boxes.insert(boxes.end(), non_pssh_box.begin(), non_pssh_box.end());
552 boxes.insert(boxes.end(), pssh_box.begin(), pssh_box.end()); 552 boxes.insert(boxes.end(), pssh_box.begin(), pssh_box.end());
553 EXPECT_FALSE(ValidatePsshInput(boxes)); 553 EXPECT_FALSE(ValidatePsshInput(boxes));
554 } 554 }
555 555
556 } // namespace media 556 } // namespace media
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