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

Unified Diff: media/formats/mp4/box_definitions.cc

Issue 2643573003: MSE: Fix Mp4 TRUN parsing overflow (Closed)
Patch Set: Proper unit test for TRUN sample_count overflow Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | media/formats/mp4/box_reader_unittest.cc » ('j') | media/formats/mp4/box_reader_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/formats/mp4/box_definitions.cc
diff --git a/media/formats/mp4/box_definitions.cc b/media/formats/mp4/box_definitions.cc
index 30c61624b78d2474012ba14a9c38816e34d8439a..83103be6a513498edaf4a7d3560161e0274852d4 100644
--- a/media/formats/mp4/box_definitions.cc
+++ b/media/formats/mp4/box_definitions.cc
@@ -9,6 +9,7 @@
#include "base/command_line.h"
#include "base/logging.h"
+#include "base/numerics/safe_math.h"
#include "base/strings/string_number_conversions.h"
#include "media/base/media_switches.h"
#include "media/base/video_types.h"
@@ -1122,16 +1123,31 @@ bool TrackFragmentRun::Parse(BoxReader* reader) {
int fields = sample_duration_present + sample_size_present +
sample_flags_present + sample_composition_time_offsets_present;
- RCHECK(reader->HasBytes(fields * sample_count));
- if (sample_duration_present)
+ // |bytes_needed| is potentially 64-bit. Cast |sample_count| from uint32_t to
+ // size_t to avoid multiplication overflow.
+ base::CheckedNumeric<size_t> bytes_needed =
+ base::CheckMul(fields, static_cast<size_t>(sample_count));
+ RCHECK_MEDIA_LOGGED(bytes_needed.IsValid(), reader->media_log(),
+ "Extreme TRUN sample count exceeds system address space");
+ RCHECK(reader->HasBytes(bytes_needed.ValueOrDie()));
DaleCurtis 2017/01/18 21:21:32 Isn't this unreachable if IsValid() fails above?
chcunningham 2017/01/18 21:52:06 Yes. Its only reachable when IsValid passes, in w
DaleCurtis 2017/01/18 21:53:04 Whoops, sorry I totally skipped over the function
+
+ if (sample_duration_present) {
+ RCHECK(sample_count <= sample_durations.max_size());
sample_durations.resize(sample_count);
- if (sample_size_present)
+ }
+ if (sample_size_present) {
+ RCHECK(sample_count <= sample_sizes.max_size());
sample_sizes.resize(sample_count);
- if (sample_flags_present)
+ }
+ if (sample_flags_present) {
+ RCHECK(sample_count <= sample_flags.max_size());
sample_flags.resize(sample_count);
- if (sample_composition_time_offsets_present)
+ }
+ if (sample_composition_time_offsets_present) {
+ RCHECK(sample_count <= sample_composition_time_offsets.max_size());
sample_composition_time_offsets.resize(sample_count);
+ }
for (uint32_t i = 0; i < sample_count; ++i) {
if (sample_duration_present)
« no previous file with comments | « no previous file | media/formats/mp4/box_reader_unittest.cc » ('j') | media/formats/mp4/box_reader_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698