Commit 69eab5cd authored by James Zern's avatar James Zern

roll libwebm snapshot

git log --no-merges --oneline 32d5ac4..a97c484
9096786 mkvparser: fix float conversion warning
84e8257 disable -Wdeprecated-declarations in legacy code
a98f495 AddGenericFrame: fix memory leak on failure
da131dd AddCuePoint: fix memory leak on failure
b0cea9c Add(Audio|Video)Track: fix memory leak on failure
5261a67 webm_info: check vp9 ParseUncompressedHeader return
85f7e2e webm_info,PrintVP9Info: validate alt ref sizes
9b97ca1 vp9_header_parser_tests: check parser return
300d6d8 CuePoint::Find: check Track pointer
50c44bb webm_info,OutputCues: fix indexing of tracks
a0d27f0 mkvparser,Block::Parse: remove incorrect assert
784fc1b vttdemux,CloseFiles: check file pointer before closing
b4522c1 .gitattributes: force mkv/webm to be treated as binary
a118f3d Add test for projection parse failures.
d398479 Add test for primary chromaticity parse failures.
9bbec4c Fix permissions on test file.
2cef4d5 mkvparser:Parse: s/FLT_MIN/-FLT_MAX/
35a3c88 mkvmuxer: Turn off estimate_file_duration_ by default
5a41830 mkvparser: Avoid double free when Chromaticity parse fails.
67e3ffa mkvparser: Avoid casts of values too large for float in
Projection elements.
...

Change-Id: I45acb22902ff0a46a5d339dc51181d5d141a8dcc
parent e3afdd89
URL: https://chromium.googlesource.com/webm/libwebm
Version: 32d5ac49414a8914ec1e1f285f3f927c6e8ec29d
Version: a97c484bfd6b5de4b1b61efe33089b55d810b412
License: BSD
License File: LICENSE.txt
......@@ -7,4 +7,4 @@ Description:
libwebm is used to handle WebM container I/O.
Local Changes:
* <none>
* Add V_AV1 codec id
......@@ -14,6 +14,7 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <ios>
......@@ -21,13 +22,23 @@ namespace libwebm {
std::string GetTempFileName() {
#if !defined _MSC_VER && !defined __MINGW32__
char temp_file_name_template[] = "libwebm_temp.XXXXXX";
std::string temp_file_name_template_str =
std::string(std::getenv("TEST_TMPDIR") ? std::getenv("TEST_TMPDIR") :
".") +
"/libwebm_temp.XXXXXX";
char* temp_file_name_template =
new char[temp_file_name_template_str.length() + 1];
memset(temp_file_name_template, 0, temp_file_name_template_str.length() + 1);
temp_file_name_template_str.copy(temp_file_name_template,
temp_file_name_template_str.length(), 0);
int fd = mkstemp(temp_file_name_template);
std::string temp_file_name =
(fd != -1) ? std::string(temp_file_name_template) : std::string();
delete[] temp_file_name_template;
if (fd != -1) {
close(fd);
return std::string(temp_file_name_template);
}
return std::string();
return temp_file_name;
#else
char tmp_file_name[_MAX_PATH];
errno_t err = tmpnam_s(tmp_file_name);
......
......@@ -7,12 +7,15 @@
// be found in the AUTHORS file in the root of the source tree.
#include "hdr_util.h"
#include <climits>
#include <cstddef>
#include <new>
#include "mkvparser/mkvparser.h"
namespace libwebm {
const int Vp9CodecFeatures::kValueNotPresent = INT_MAX;
bool CopyPrimaryChromaticity(const mkvparser::PrimaryChromaticity& parser_pc,
PrimaryChromaticityPtr* muxer_pc) {
muxer_pc->reset(new (std::nothrow)
......@@ -29,9 +32,9 @@ bool MasteringMetadataValuePresent(double value) {
bool CopyMasteringMetadata(const mkvparser::MasteringMetadata& parser_mm,
mkvmuxer::MasteringMetadata* muxer_mm) {
if (MasteringMetadataValuePresent(parser_mm.luminance_max))
muxer_mm->luminance_max = parser_mm.luminance_max;
muxer_mm->set_luminance_max(parser_mm.luminance_max);
if (MasteringMetadataValuePresent(parser_mm.luminance_min))
muxer_mm->luminance_min = parser_mm.luminance_min;
muxer_mm->set_luminance_min(parser_mm.luminance_min);
PrimaryChromaticityPtr r_ptr(NULL);
PrimaryChromaticityPtr g_ptr(NULL);
......@@ -73,34 +76,37 @@ bool CopyColour(const mkvparser::Colour& parser_colour,
return false;
if (ColourValuePresent(parser_colour.matrix_coefficients))
muxer_colour->matrix_coefficients = parser_colour.matrix_coefficients;
muxer_colour->set_matrix_coefficients(parser_colour.matrix_coefficients);
if (ColourValuePresent(parser_colour.bits_per_channel))
muxer_colour->bits_per_channel = parser_colour.bits_per_channel;
if (ColourValuePresent(parser_colour.chroma_subsampling_horz))
muxer_colour->chroma_subsampling_horz =
parser_colour.chroma_subsampling_horz;
if (ColourValuePresent(parser_colour.chroma_subsampling_vert))
muxer_colour->chroma_subsampling_vert =
parser_colour.chroma_subsampling_vert;
muxer_colour->set_bits_per_channel(parser_colour.bits_per_channel);
if (ColourValuePresent(parser_colour.chroma_subsampling_horz)) {
muxer_colour->set_chroma_subsampling_horz(
parser_colour.chroma_subsampling_horz);
}
if (ColourValuePresent(parser_colour.chroma_subsampling_vert)) {
muxer_colour->set_chroma_subsampling_vert(
parser_colour.chroma_subsampling_vert);
}
if (ColourValuePresent(parser_colour.cb_subsampling_horz))
muxer_colour->cb_subsampling_horz = parser_colour.cb_subsampling_horz;
muxer_colour->set_cb_subsampling_horz(parser_colour.cb_subsampling_horz);
if (ColourValuePresent(parser_colour.cb_subsampling_vert))
muxer_colour->cb_subsampling_vert = parser_colour.cb_subsampling_vert;
muxer_colour->set_cb_subsampling_vert(parser_colour.cb_subsampling_vert);
if (ColourValuePresent(parser_colour.chroma_siting_horz))
muxer_colour->chroma_siting_horz = parser_colour.chroma_siting_horz;
muxer_colour->set_chroma_siting_horz(parser_colour.chroma_siting_horz);
if (ColourValuePresent(parser_colour.chroma_siting_vert))
muxer_colour->chroma_siting_vert = parser_colour.chroma_siting_vert;
muxer_colour->set_chroma_siting_vert(parser_colour.chroma_siting_vert);
if (ColourValuePresent(parser_colour.range))
muxer_colour->range = parser_colour.range;
if (ColourValuePresent(parser_colour.transfer_characteristics))
muxer_colour->transfer_characteristics =
parser_colour.transfer_characteristics;
muxer_colour->set_range(parser_colour.range);
if (ColourValuePresent(parser_colour.transfer_characteristics)) {
muxer_colour->set_transfer_characteristics(
parser_colour.transfer_characteristics);
}
if (ColourValuePresent(parser_colour.primaries))
muxer_colour->primaries = parser_colour.primaries;
muxer_colour->set_primaries(parser_colour.primaries);
if (ColourValuePresent(parser_colour.max_cll))
muxer_colour->max_cll = parser_colour.max_cll;
muxer_colour->set_max_cll(parser_colour.max_cll);
if (ColourValuePresent(parser_colour.max_fall))
muxer_colour->max_fall = parser_colour.max_fall;
muxer_colour->set_max_fall(parser_colour.max_fall);
if (parser_colour.mastering_metadata) {
mkvmuxer::MasteringMetadata muxer_mm;
......@@ -116,8 +122,8 @@ bool CopyColour(const mkvparser::Colour& parser_colour,
//
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | ID Byte | Length | |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
// | ID Byte | Length | |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
// | |
// : Bytes 1..Length of Codec Feature :
// | |
......@@ -132,51 +138,83 @@ bool CopyColour(const mkvparser::Colour& parser_colour,
//
// The X bit is reserved.
//
// Currently only profile level is supported. ID byte must be set to 1, and
// length must be 1. Supported values are:
//
// 10: Level 1
// 11: Level 1.1
// 20: Level 2
// 21: Level 2.1
// 30: Level 3
// 31: Level 3.1
// 40: Level 4
// 41: Level 4.1
// 50: Level 5
// 51: Level 5.1
// 52: Level 5.2
// 60: Level 6
// 61: Level 6.1
// 62: Level 6.2
//
// See the following link for more information:
// http://www.webmproject.org/vp9/profiles/
int ParseVpxCodecPrivate(const uint8_t* private_data, int32_t length) {
const int kVpxCodecPrivateLength = 3;
if (!private_data || length != kVpxCodecPrivateLength)
return 0;
const uint8_t id_byte = *private_data;
if (id_byte != 1)
return 0;
const int kVpxProfileLength = 1;
const uint8_t length_byte = private_data[1];
if (length_byte != kVpxProfileLength)
return 0;
const int level = static_cast<int>(private_data[2]);
const int kNumLevels = 14;
const int levels[kNumLevels] = {10, 11, 20, 21, 30, 31, 40,
41, 50, 51, 52, 60, 61, 62};
bool ParseVpxCodecPrivate(const uint8_t* private_data, int32_t length,
Vp9CodecFeatures* features) {
const int kVpxCodecPrivateMinLength = 3;
if (!private_data || !features || length < kVpxCodecPrivateMinLength)
return false;
for (int i = 0; i < kNumLevels; ++i) {
if (level == levels[i])
return level;
}
const uint8_t kVp9ProfileId = 1;
const uint8_t kVp9LevelId = 2;
const uint8_t kVp9BitDepthId = 3;
const uint8_t kVp9ChromaSubsamplingId = 4;
const int kVpxFeatureLength = 1;
int offset = 0;
// Set features to not set.
features->profile = Vp9CodecFeatures::kValueNotPresent;
features->level = Vp9CodecFeatures::kValueNotPresent;
features->bit_depth = Vp9CodecFeatures::kValueNotPresent;
features->chroma_subsampling = Vp9CodecFeatures::kValueNotPresent;
do {
const uint8_t id_byte = private_data[offset++];
const uint8_t length_byte = private_data[offset++];
if (length_byte != kVpxFeatureLength)
return false;
if (id_byte == kVp9ProfileId) {
const int priv_profile = static_cast<int>(private_data[offset++]);
if (priv_profile < 0 || priv_profile > 3)
return false;
if (features->profile != Vp9CodecFeatures::kValueNotPresent &&
features->profile != priv_profile) {
return false;
}
features->profile = priv_profile;
} else if (id_byte == kVp9LevelId) {
const int priv_level = static_cast<int>(private_data[offset++]);
const int kNumLevels = 14;
const int levels[kNumLevels] = {10, 11, 20, 21, 30, 31, 40,
41, 50, 51, 52, 60, 61, 62};
for (int i = 0; i < kNumLevels; ++i) {
if (priv_level == levels[i]) {
if (features->level != Vp9CodecFeatures::kValueNotPresent &&
features->level != priv_level) {
return false;
}
features->level = priv_level;
break;
}
}
if (features->level == Vp9CodecFeatures::kValueNotPresent)
return false;
} else if (id_byte == kVp9BitDepthId) {
const int priv_profile = static_cast<int>(private_data[offset++]);
if (priv_profile != 8 && priv_profile != 10 && priv_profile != 12)
return false;
if (features->bit_depth != Vp9CodecFeatures::kValueNotPresent &&
features->bit_depth != priv_profile) {
return false;
}
features->bit_depth = priv_profile;
} else if (id_byte == kVp9ChromaSubsamplingId) {
const int priv_profile = static_cast<int>(private_data[offset++]);
if (priv_profile != 0 && priv_profile != 2 && priv_profile != 3)
return false;
if (features->chroma_subsampling != Vp9CodecFeatures::kValueNotPresent &&
features->chroma_subsampling != priv_profile) {
return false;
}
features->chroma_subsampling = priv_profile;
} else {
// Invalid ID.
return false;
}
} while (offset + kVpxCodecPrivateMinLength <= length);
return 0;
return true;
}
} // namespace libwebm
......@@ -28,7 +28,34 @@ namespace libwebm {
// TODO(tomfinegan): These should be moved to libwebm_utils once c++11 is
// required by libwebm.
// Features of the VP9 codec that may be set in the CodecPrivate of a VP9 video
// stream. A value of kValueNotPresent represents that the value was not set in
// the CodecPrivate.
struct Vp9CodecFeatures {
static const int kValueNotPresent;
Vp9CodecFeatures()
: profile(kValueNotPresent),
level(kValueNotPresent),
bit_depth(kValueNotPresent),
chroma_subsampling(kValueNotPresent) {}
~Vp9CodecFeatures() {}
int profile;
int level;
int bit_depth;
int chroma_subsampling;
};
// disable deprecation warnings for auto_ptr
#if defined(__GNUC__) && __GNUC__ >= 5
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
typedef std::auto_ptr<mkvmuxer::PrimaryChromaticity> PrimaryChromaticityPtr;
#if defined(__GNUC__) && __GNUC__ >= 5
#pragma GCC diagnostic pop
#endif
bool CopyPrimaryChromaticity(const mkvparser::PrimaryChromaticity& parser_pc,
PrimaryChromaticityPtr* muxer_pc);
......@@ -43,8 +70,9 @@ bool ColourValuePresent(long long value);
bool CopyColour(const mkvparser::Colour& parser_colour,
mkvmuxer::Colour* muxer_colour);
// Returns VP9 profile upon success or 0 upon failure.
int ParseVpxCodecPrivate(const uint8_t* private_data, int32_t length);
// Returns true if |features| is set to one or more valid values.
bool ParseVpxCodecPrivate(const uint8_t* private_data, int32_t length,
Vp9CodecFeatures* features);
} // namespace libwebm
......
......@@ -124,6 +124,14 @@ enum MkvId {
kMkvLuminanceMin = 0x55DA,
// end mastering metadata
// end colour
// projection
kMkvProjection = 0x7670,
kMkvProjectionType = 0x7671,
kMkvProjectionPrivate = 0x7672,
kMkvProjectionPoseYaw = 0x7673,
kMkvProjectionPosePitch = 0x7674,
kMkvProjectionPoseRoll = 0x7675,
// end projection
// audio
kMkvAudio = 0xE1,
kMkvSamplingFrequency = 0xB5,
......
This diff is collapsed.
This diff is collapsed.
......@@ -8,87 +8,104 @@
#ifndef MKVMUXER_MKVMUXERUTIL_H_
#define MKVMUXER_MKVMUXERUTIL_H_
#include <stdint.h>
#include "mkvmuxertypes.h"
#include "stdint.h"
namespace mkvmuxer {
class Cluster;
class Frame;
class IMkvWriter;
const uint64_t kEbmlUnknownValue = 0x01FFFFFFFFFFFFFFULL;
const int64_t kMaxBlockTimecode = 0x07FFFLL;
// TODO(tomfinegan): mkvmuxer:: integer types continue to be used here because
// changing them causes pain for downstream projects. It would be nice if a
// solution that allows removal of the mkvmuxer:: integer types while avoiding
// pain for downstream users of libwebm. Considering that mkvmuxerutil.{cc,h}
// are really, for the great majority of cases, EBML size calculation and writer
// functions, perhaps a more EBML focused utility would be the way to go as a
// first step.
const uint64 kEbmlUnknownValue = 0x01FFFFFFFFFFFFFFULL;
const int64 kMaxBlockTimecode = 0x07FFFLL;
// Writes out |value| in Big Endian order. Returns 0 on success.
int32_t SerializeInt(IMkvWriter* writer, int64_t value, int32_t size);
int32 SerializeInt(IMkvWriter* writer, int64 value, int32 size);
// Returns the size in bytes of the element.
int32_t GetUIntSize(uint64_t value);
int32_t GetIntSize(int64_t value);
int32_t GetCodedUIntSize(uint64_t value);
uint64_t EbmlMasterElementSize(uint64_t type, uint64_t value);
uint64_t EbmlElementSize(uint64_t type, int64_t value);
uint64_t EbmlElementSize(uint64_t type, uint64_t value);
uint64_t EbmlElementSize(uint64_t type, float value);
uint64_t EbmlElementSize(uint64_t type, const char* value);
uint64_t EbmlElementSize(uint64_t type, const uint8_t* value, uint64_t size);
uint64_t EbmlDateElementSize(uint64_t type);
int32 GetUIntSize(uint64 value);
int32 GetIntSize(int64 value);
int32 GetCodedUIntSize(uint64 value);
uint64 EbmlMasterElementSize(uint64 type, uint64 value);
uint64 EbmlElementSize(uint64 type, int64 value);
uint64 EbmlElementSize(uint64 type, uint64 value);
uint64 EbmlElementSize(uint64 type, float value);
uint64 EbmlElementSize(uint64 type, const char* value);
uint64 EbmlElementSize(uint64 type, const uint8* value, uint64 size);
uint64 EbmlDateElementSize(uint64 type);
// Returns the size in bytes of the element assuming that the element was
// written using |fixed_size| bytes. If |fixed_size| is set to zero, then it
// computes the necessary number of bytes based on |value|.
uint64_t EbmlElementSize(uint64_t type, uint64_t value, uint64_t fixed_size);
uint64 EbmlElementSize(uint64 type, uint64 value, uint64 fixed_size);
// Creates an EBML coded number from |value| and writes it out. The size of
// the coded number is determined by the value of |value|. |value| must not
// be in a coded form. Returns 0 on success.
int32_t WriteUInt(IMkvWriter* writer, uint64_t value);
int32 WriteUInt(IMkvWriter* writer, uint64 value);
// Creates an EBML coded number from |value| and writes it out. The size of
// the coded number is determined by the value of |size|. |value| must not
// be in a coded form. Returns 0 on success.
int32_t WriteUIntSize(IMkvWriter* writer, uint64_t value, int32_t size);
int32 WriteUIntSize(IMkvWriter* writer, uint64 value, int32 size);
// Output an Mkv master element. Returns true if the element was written.
bool WriteEbmlMasterElement(IMkvWriter* writer, uint64_t value, uint64_t size);
bool WriteEbmlMasterElement(IMkvWriter* writer, uint64 value, uint64 size);
// Outputs an Mkv ID, calls |IMkvWriter::ElementStartNotify|, and passes the
// ID to |SerializeInt|. Returns 0 on success.
int32_t WriteID(IMkvWriter* writer, uint64_t type);
int32 WriteID(IMkvWriter* writer, uint64 type);
// Output an Mkv non-master element. Returns true if the element was written.
bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, uint64_t value);
bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, int64_t value);
bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, float value);
bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, const char* value);
bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, const uint8_t* value,
uint64_t size);
bool WriteEbmlDateElement(IMkvWriter* writer, uint64_t type, int64_t value);
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, uint64 value);
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, int64 value);
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, float value);
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, const char* value);
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, const uint8* value,
uint64 size);
bool WriteEbmlDateElement(IMkvWriter* writer, uint64 type, int64 value);
// Output an Mkv non-master element using fixed size. The element will be
// written out using exactly |fixed_size| bytes. If |fixed_size| is set to zero
// then it computes the necessary number of bytes based on |value|. Returns true
// if the element was written.
bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, uint64_t value,
uint64_t fixed_size);
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, uint64 value,
uint64 fixed_size);
// Output a Mkv Frame. It decides the correct element to write (Block vs
// SimpleBlock) based on the parameters of the Frame.
uint64_t WriteFrame(IMkvWriter* writer, const Frame* const frame,
Cluster* cluster);
uint64 WriteFrame(IMkvWriter* writer, const Frame* const frame,
Cluster* cluster);
// Output a void element. |size| must be the entire size in bytes that will be
// void. The function will calculate the size of the void header and subtract
// it from |size|.
uint64_t WriteVoidElement(IMkvWriter* writer, uint64_t size);
uint64 WriteVoidElement(IMkvWriter* writer, uint64 size);
// Returns the version number of the muxer in |major|, |minor|, |build|,
// and |revision|.
void GetVersion(int32_t* major, int32_t* minor, int32_t* build,
int32_t* revision);
void GetVersion(int32* major, int32* minor, int32* build, int32* revision);
// Returns a random number to be used for UID, using |seed| to seed
// the random-number generator (see POSIX rand_r() for semantics).
uint64_t MakeUID(unsigned int* seed);
uint64 MakeUID(unsigned int* seed);
// Colour field validation helpers. All return true when |value| is valid.
bool IsMatrixCoefficientsValueValid(uint64_t value);
bool IsChromaSitingHorzValueValid(uint64_t value);
bool IsChromaSitingVertValueValid(uint64_t value);
bool IsColourRangeValueValid(uint64_t value);
bool IsTransferCharacteristicsValueValid(uint64_t value);
bool IsPrimariesValueValid(uint64_t value);
} // namespace mkvmuxer
......
......@@ -8,6 +8,8 @@
#include "mkvmuxer/mkvwriter.h"
#include <sys/types.h>
#ifdef _MSC_VER
#include <share.h> // for _SH_DENYWR
#endif
......@@ -77,7 +79,7 @@ int32 MkvWriter::Position(int64 position) {
#ifdef _MSC_VER
return _fseeki64(file_, position, SEEK_SET);
#else
return fseek(file_, position, SEEK_SET);
return fseeko(file_, static_cast<off_t>(position), SEEK_SET);
#endif
}
......
......@@ -22,9 +22,15 @@
#include "common/webmids.h"
// disable deprecation warnings for auto_ptr
#if defined(__GNUC__) && __GNUC__ >= 5
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
namespace mkvparser {
const float MasteringMetadata::kValueNotPresent = FLT_MAX;
const long long Colour::kValueNotPresent = LLONG_MAX;
const float Projection::kValueNotPresent = FLT_MAX;
#ifdef MSC_COMPAT
inline bool isnan(double val) { return !!_isnan(val); }
......@@ -1475,6 +1481,8 @@ long Segment::Load() {
}
}
SeekHead::Entry::Entry() : id(0), pos(0), element_start(0), element_size(0) {}
SeekHead::SeekHead(Segment* pSegment, long long start, long long size_,
long long element_start, long long element_size)
: m_pSegment(pSegment),
......@@ -1525,15 +1533,19 @@ long SeekHead::Parse() {
if (pos != stop)
return E_FILE_FORMAT_INVALID;
m_entries = new (std::nothrow) Entry[entry_count];
if (entry_count > 0) {
m_entries = new (std::nothrow) Entry[entry_count];
if (m_entries == NULL)
return -1;
if (m_entries == NULL)
return -1;
}
m_void_elements = new (std::nothrow) VoidElement[void_element_count];
if (void_element_count > 0) {
m_void_elements = new (std::nothrow) VoidElement[void_element_count];
if (m_void_elements == NULL)
return -1;
if (m_void_elements == NULL)
return -1;
}
// now parse the entries and void elements
......@@ -1552,14 +1564,14 @@ long SeekHead::Parse() {
if (status < 0) // error
return status;
if (id == libwebm::kMkvSeek) {
if (id == libwebm::kMkvSeek && entry_count > 0) {
if (ParseEntry(pReader, pos, size, pEntry)) {
Entry& e = *pEntry++;
e.element_start = idpos;
e.element_size = (pos + size) - idpos;
}
} else if (id == libwebm::kMkvVoid) {
} else if (id == libwebm::kMkvVoid && void_element_count > 0) {
VoidElement& e = *pVoidElement++;
e.element_start = idpos;
......@@ -1766,18 +1778,7 @@ bool SeekHead::ParseEntry(IMkvReader* pReader, long long start, long long size_,
if ((pos + seekIdSize) > stop)
return false;
// Note that the SeekId payload really is serialized
// as a "Matroska integer", not as a plain binary value.
// In fact, Matroska requires that ID values in the
// stream exactly match the binary representation as listed
// in the Matroska specification.
//
// This parser is more liberal, and permits IDs to have
// any width. (This could make the representation in the stream
// different from what's in the spec, but it doesn't matter here,
// since we always normalize "Matroska integer" values.)
pEntry->id = ReadUInt(pReader, pos, len); // payload
pEntry->id = ReadID(pReader, pos, len); // payload
if (pEntry->id <= 0)
return false;
......@@ -2434,7 +2435,9 @@ bool CuePoint::TrackPosition::Parse(IMkvReader* pReader, long long start_,
}
const CuePoint::TrackPosition* CuePoint::Find(const Track* pTrack) const {
assert(pTrack);
if (pTrack == NULL) {
return NULL;
}
const long long n = pTrack->GetNumber();
......@@ -4034,7 +4037,7 @@ long SegmentInfo::Parse() {
}
const double rollover_check = m_duration * m_timecodeScale;
if (rollover_check > LLONG_MAX)
if (rollover_check > static_cast<double>(LLONG_MAX))
return E_FILE_FORMAT_INVALID;
if (pos != stop)
......@@ -4125,7 +4128,7 @@ ContentEncoding::~ContentEncoding() {
}
const ContentEncoding::ContentCompression*
ContentEncoding::GetCompressionByIndex(unsigned long idx) const {
ContentEncoding::GetCompressionByIndex(unsigned long idx) const {
const ptrdiff_t count = compression_entries_end_ - compression_entries_;
assert(count >= 0);
......@@ -4983,29 +4986,27 @@ bool PrimaryChromaticity::Parse(IMkvReader* reader, long long read_pos,
if (!reader)
return false;
std::auto_ptr<PrimaryChromaticity> chromaticity_ptr;
if (!*chromaticity) {
chromaticity_ptr.reset(new PrimaryChromaticity());
} else {
chromaticity_ptr.reset(*chromaticity);
}
if (!*chromaticity)
*chromaticity = new PrimaryChromaticity();
if (!chromaticity_ptr.get())
if (!*chromaticity)
return false;
float* value = is_x ? &chromaticity_ptr->x : &chromaticity_ptr->y;
PrimaryChromaticity* pc = *chromaticity;
float* value = is_x ? &pc->x : &pc->y;
double parser_value = 0;
const long long value_parse_status =
const long long parse_status =
UnserializeFloat(reader, read_pos, value_size, parser_value);
*value = static_cast<float>(parser_value);
if (value_parse_status < 0 || *value < 0.0 || *value > 1.0)
// Valid range is [0, 1]. Make sure the double is representable as a float
// before casting.
if (parse_status < 0 || parser_value < 0.0 || parser_value > 1.0 ||
(parser_value > 0.0 && parser_value < FLT_MIN))
return false;
*chromaticity = chromaticity_ptr.release();
*value = static_cast<float>(parser_value);
return true;
}
......@@ -5188,11 +5189,94 @@ bool Colour::Parse(IMkvReader* reader, long long colour_start,
return true;
}
bool Projection::Parse(IMkvReader* reader, long long start, long long size,
Projection** projection) {
if (!reader || *projection)
return false;
std::auto_ptr<Projection> projection_ptr(new Projection());
if (!projection_ptr.get())
return false;
const long long end = start + size;
long long read_pos = start;
while (read_pos < end) {
long long child_id = 0;
long long child_size = 0;
const long long status =
ParseElementHeader(reader, read_pos, end, child_id, child_size);
if (status < 0)
return false;
if (child_id == libwebm::kMkvProjectionType) {
long long projection_type = kTypeNotPresent;
projection_type = UnserializeUInt(reader, read_pos, child_size);
if (projection_type < 0)
return false;
projection_ptr->type = static_cast<ProjectionType>(projection_type);
} else if (child_id == libwebm::kMkvProjectionPrivate) {
unsigned char* data = SafeArrayAlloc<unsigned char>(1, child_size);
if (data == NULL)
return false;
const int status =
reader->Read(read_pos, static_cast<long>(child_size), data);
if (status) {
delete[] data;
return false;
}
projection_ptr->private_data = data;
projection_ptr->private_data_length = static_cast<size_t>(child_size);
} else {