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

Unified Diff: media/mp4/box_reader.cc

Issue 10823139: Set error on unrecognized top-level BMFF boxes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove FourCCs used only for testing Created 8 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 side-by-side diff with in-line comments
Download patch
Index: media/mp4/box_reader.cc
diff --git a/media/mp4/box_reader.cc b/media/mp4/box_reader.cc
index 8892a43991cbd1e9b976134c1ca00f640baaca83..1d86e7bdf01a54c99e42edbe670fce2efe6a35f5 100644
--- a/media/mp4/box_reader.cc
+++ b/media/mp4/box_reader.cc
@@ -10,6 +10,7 @@
#include <set>
#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
#include "media/mp4/box_definitions.h"
#include "media/mp4/rcheck.h"
@@ -95,14 +96,24 @@ BoxReader::~BoxReader() {
}
}
+// static
BoxReader* BoxReader::ReadTopLevelBox(const uint8* buf,
const int buf_size,
bool* err) {
- BoxReader* reader = new BoxReader(buf, buf_size);
- if (reader->ReadHeader(err) && reader->size() <= buf_size) {
- return reader;
+ scoped_ptr<BoxReader> reader(new BoxReader(buf, buf_size));
+ if (!reader->ReadHeader(err))
+ return NULL;
+
+ if (!IsValidTopLevelBox(reader->type())) {
+ LOG(WARNING) << "Unrecognized top-level box type 0x"
+ << std::hex << reader->type();
acolwell GONE FROM CHROMIUM 2012/08/02 20:38:18 Any reason not to use FourCCToString() here like y
strobe_ 2012/08/02 21:27:50 In the expected case of misregistration, the box t
acolwell GONE FROM CHROMIUM 2012/08/02 21:40:25 Ok. Makes sense.
+ *err = true;
+ return NULL;
}
- delete reader;
+
+ if (reader->size() <= buf_size)
+ return reader.release();
+
return NULL;
}
@@ -114,11 +125,33 @@ bool BoxReader::StartTopLevelBox(const uint8* buf,
bool* err) {
BoxReader reader(buf, buf_size);
if (!reader.ReadHeader(err)) return false;
+ if (!IsValidTopLevelBox(reader.type())) {
+ *err = true;
+ return false;
+ }
*type = reader.type();
*box_size = reader.size();
return true;
}
+// static
+bool BoxReader::IsValidTopLevelBox(const FourCC& type) {
+ return (type == FOURCC_FTYP ||
acolwell GONE FROM CHROMIUM 2012/08/02 20:38:18 nit: WDYT about using a switch() here w/ a return
strobe_ 2012/08/02 21:27:50 Done.
+ type == FOURCC_PDIN ||
+ type == FOURCC_MOOV ||
+ type == FOURCC_MOOF ||
+ type == FOURCC_MFRA ||
+ type == FOURCC_MDAT ||
+ type == FOURCC_FREE ||
+ type == FOURCC_SKIP ||
+ type == FOURCC_META ||
+ type == FOURCC_MECO ||
+ type == FOURCC_STYP ||
+ type == FOURCC_SIDX ||
+ type == FOURCC_SSIX ||
+ type == FOURCC_PRFT);
+}
+
bool BoxReader::ScanChildren() {
DCHECK(!scanned_);
scanned_ = true;

Powered by Google App Engine
This is Rietveld 408576698