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

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

Issue 2648433002: MSE: Fix Mp4 SAIO parsing overflow (Closed)
Patch Set: Feedback 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') | no next file with comments »
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 83103be6a513498edaf4a7d3560161e0274852d4..f541ee633760d0e736a733ab470fbbb30f6a47f6 100644
--- a/media/formats/mp4/box_definitions.cc
+++ b/media/formats/mp4/box_definitions.cc
@@ -124,8 +124,17 @@ bool SampleAuxiliaryInformationOffset::Parse(BoxReader* reader) {
RCHECK(reader->SkipBytes(8));
uint32_t count;
- RCHECK(reader->Read4(&count) &&
- reader->HasBytes(count * (reader->version() == 1 ? 8 : 4)));
+ RCHECK(reader->Read4(&count));
+ int bytes_per_offset = reader->version() == 1 ? 8 : 4;
+
+ // Cast |count| to size_t before multiplying to support maximum platform size.
+ base::CheckedNumeric<size_t> bytes_needed =
+ base::CheckMul(bytes_per_offset, static_cast<size_t>(count));
+ RCHECK_MEDIA_LOGGED(bytes_needed.IsValid(), reader->media_log(),
+ "Extreme SAIO count exceeds implementation limit.");
+ RCHECK(reader->HasBytes(bytes_needed.ValueOrDie()));
+
+ RCHECK(count <= offsets.max_size());
offsets.resize(count);
for (uint32_t i = 0; i < count; i++) {
@@ -1124,8 +1133,8 @@ bool TrackFragmentRun::Parse(BoxReader* reader) {
int fields = sample_duration_present + sample_size_present +
sample_flags_present + sample_composition_time_offsets_present;
- // |bytes_needed| is potentially 64-bit. Cast |sample_count| from uint32_t to
- // size_t to avoid multiplication overflow.
+ // Cast |sample_count| to size_t before multiplying to support maximum
+ // platform size.
base::CheckedNumeric<size_t> bytes_needed =
base::CheckMul(fields, static_cast<size_t>(sample_count));
RCHECK_MEDIA_LOGGED(bytes_needed.IsValid(), reader->media_log(),
« no previous file with comments | « no previous file | media/formats/mp4/box_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698