From 42044e93f5784b6efcef9845e72a3e41ba6a8fd4 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Tue, 10 Aug 2010 19:04:58 +0000 Subject: [PATCH] more safety on the Binary buffer handling in case we run out of memory git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/libebml@491 a6f86f6d-0131-4f8e-9e7b-e335508773d5 --- ChangeLog | 1 + src/EbmlBinary.cpp | 6 ++++-- src/EbmlMaster.cpp | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index a1daee3..f718482 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2010-08-xx robux4 New 1.1.1 version: - no need to put the internal code of EbmlCrc32 in the public header + - more safety on the Binary buffer handling in case we run out of memory 2010-07-xx robux4 New 1.1.0 version: diff --git a/src/EbmlBinary.cpp b/src/EbmlBinary.cpp index cf27d80..3282267 100644 --- a/src/EbmlBinary.cpp +++ b/src/EbmlBinary.cpp @@ -37,6 +37,7 @@ #include #include "ebml/EbmlBinary.h" +#include "ebml/StdIOCallback.h" START_LIBEBML_NAMESPACE @@ -84,14 +85,15 @@ filepos_t EbmlBinary::ReadData(IOCallback & input, ScopeMode ReadFully) if (Data != NULL) free(Data); - if (ReadFully == SCOPE_NO_DATA) + if (ReadFully == SCOPE_NO_DATA || !GetSize()) { Data = NULL; return GetSize(); } Data = (binary *)malloc(GetSize() * sizeof(binary)); - assert(Data != NULL); + if (Data == NULL) + throw CRTError::CRTError("Error allocating data"); SetValueIsSet(); return input.read(Data, GetSize()); } diff --git a/src/EbmlMaster.cpp b/src/EbmlMaster.cpp index f5ce26e..9db6aed 100644 --- a/src/EbmlMaster.cpp +++ b/src/EbmlMaster.cpp @@ -278,7 +278,7 @@ EbmlElement *EbmlMaster::FindFirstElt(const EbmlCallbacks & Callbacks, bool bCre size_t Index; for (Index = 0; Index < ElementList.size(); Index++) { - if (EbmlId(*(ElementList[Index])) == EBML_INFO_ID(Callbacks)) + if (ElementList[Index] && EbmlId(*(ElementList[Index])) == EBML_INFO_ID(Callbacks)) return ElementList[Index]; }