Support 64 bit mdat box size

Change-Id: I38be77d2d13eceaeeda6f3ff270c8d7cd1d2a300
This commit is contained in:
KongQun Yang 2014-05-05 14:49:45 -07:00
parent 815b90753f
commit 80a60b7ef2
3 changed files with 21 additions and 8 deletions

View File

@ -6,6 +6,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/strings/stringprintf.h"
#include "media/formats/mp4/box.h" #include "media/formats/mp4/box.h"
namespace media { namespace media {
@ -54,7 +55,7 @@ BoxReader* BoxReader::ReadTopLevelBox(const uint8* buf,
bool BoxReader::StartTopLevelBox(const uint8* buf, bool BoxReader::StartTopLevelBox(const uint8* buf,
const size_t buf_size, const size_t buf_size,
FourCC* type, FourCC* type,
int* box_size, uint64* box_size,
bool* err) { bool* err) {
BoxReader reader(buf, buf_size); BoxReader reader(buf, buf_size);
if (!reader.ReadHeader(err)) if (!reader.ReadHeader(err))
@ -145,7 +146,9 @@ bool BoxReader::ReadHeader(bool* err) {
return false; return false;
if (size == 0) { if (size == 0) {
// Media Source specific: we do not support boxes that run to EOS. // Boxes that run to EOS are not supported.
NOTIMPLEMENTED() << base::StringPrintf("Box '%s' run to EOS.",
FourCCToString(type_).c_str());
*err = true; *err = true;
return false; return false;
} else if (size == 1) { } else if (size == 1) {
@ -153,10 +156,20 @@ bool BoxReader::ReadHeader(bool* err) {
return false; return false;
} }
// Implementation-specific: support for boxes larger than 2^31 has been // The box should have at least the size of what have been parsed.
// removed. if (size < pos()) {
if (size < static_cast<uint64>(pos()) || LOG(ERROR) << base::StringPrintf("Box '%s' with size (%lu) is invalid.",
size > static_cast<uint64>(kint32max)) { FourCCToString(type_).c_str(),
size);
*err = true;
return false;
}
// 'mdat' box could have a 64-bit size; other boxes should be very small.
if (size > static_cast<uint64>(kint32max) && type_ != FOURCC_MDAT) {
LOG(ERROR) << base::StringPrintf("Box '%s' size (%lu) is too large.",
FourCCToString(type_).c_str(),
size);
*err = true; *err = true;
return false; return false;
} }

View File

@ -50,7 +50,7 @@ class BoxReader : public BufferReader {
static bool StartTopLevelBox(const uint8* buf, static bool StartTopLevelBox(const uint8* buf,
const size_t buf_size, const size_t buf_size,
FourCC* type, FourCC* type,
int* box_size, uint64* box_size,
bool* err) WARN_UNUSED_RESULT; bool* err) WARN_UNUSED_RESULT;
/// @return true if @a type is recognized to be the fourcc of a top-level box, /// @return true if @a type is recognized to be the fourcc of a top-level box,

View File

@ -433,7 +433,7 @@ bool MP4MediaParser::ReadAndDiscardMDATsUntil(const int64 offset) {
queue_.PeekAt(mdat_tail_, &buf, &size); queue_.PeekAt(mdat_tail_, &buf, &size);
FourCC type; FourCC type;
int box_sz; uint64 box_sz;
if (!BoxReader::StartTopLevelBox(buf, size, &type, &box_sz, &err)) if (!BoxReader::StartTopLevelBox(buf, size, &type, &box_sz, &err))
break; break;