libebml: fix a potential MaxSizeRead issue when reading a Master with unknown size

git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/libebml@279 a6f86f6d-0131-4f8e-9e7b-e335508773d5
This commit is contained in:
Steve Lhomme 2010-05-27 15:51:00 +00:00
parent 3fff7041d2
commit c59c4616d3

View File

@ -409,14 +409,19 @@ void EbmlMaster::Read(EbmlStream & inDataStream, const EbmlSemanticContext & sCo
} }
} }
ElementList.clear(); ElementList.clear();
uint64 MaxSizeToRead = GetSize(); uint64 MaxSizeToRead;
if (IsFiniteSize())
MaxSizeToRead = GetSize();
else
MaxSizeToRead = 0x7FFFFFFF;
// read blocks and discard the ones we don't care about // read blocks and discard the ones we don't care about
if (MaxSizeToRead > 0 || !IsFiniteSize()) if (MaxSizeToRead > 0)
{ {
inDataStream.I_O().setFilePointer(GetSizePosition() + GetSizeLength(), seek_beginning); inDataStream.I_O().setFilePointer(GetSizePosition() + GetSizeLength(), seek_beginning);
ElementLevelA = inDataStream.FindNextElement(sContext, UpperEltFound, MaxSizeToRead, AllowDummyElt); ElementLevelA = inDataStream.FindNextElement(sContext, UpperEltFound, MaxSizeToRead, AllowDummyElt);
while (ElementLevelA != NULL && UpperEltFound <= 0 && (MaxSizeToRead > 0 || !IsFiniteSize())) { while (ElementLevelA != NULL && UpperEltFound <= 0 && MaxSizeToRead > 0) {
if (IsFiniteSize()) if (IsFiniteSize())
MaxSizeToRead = GetEndPosition() - ElementLevelA->GetEndPosition(); // even if it's the default value MaxSizeToRead = GetEndPosition() - ElementLevelA->GetEndPosition(); // even if it's the default value
if (!AllowDummyElt && ElementLevelA->IsDummy()) { if (!AllowDummyElt && ElementLevelA->IsDummy()) {
@ -446,9 +451,8 @@ void EbmlMaster::Read(EbmlStream & inDataStream, const EbmlSemanticContext & sCo
goto processCrc; goto processCrc;
} }
if (MaxSizeToRead <= 0) { if (MaxSizeToRead <= 0)
goto processCrc;// this level is finished goto processCrc;// this level is finished
}
ElementLevelA = inDataStream.FindNextElement(sContext, UpperEltFound, MaxSizeToRead, AllowDummyElt); ElementLevelA = inDataStream.FindNextElement(sContext, UpperEltFound, MaxSizeToRead, AllowDummyElt);
} }