Skip to content

Commit

Permalink
check the element size is valid before creating it
Browse files Browse the repository at this point in the history
  • Loading branch information
robUx4 committed Feb 26, 2024
1 parent e8be479 commit 8aa4cd3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ebml/EbmlElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ class EBML_DLL_API EbmlElement {
\return a DummyRawElement if the element is unknown or nullptr if the element dummy is not allowed
*/
static EbmlElement *CreateElementUsingContext(const EbmlId & aID, const EbmlSemanticContext & Context, int & LowLevel, bool IsGlobalContext,
bool AsInfiniteSize,
std::uint64_t WithSize, bool AsInfiniteSize,
bool bAllowDummy = false, unsigned int MaxLowerLevel = 1);

filepos_t RenderHead(IOCallback & output, bool bForceRender, const ShouldWrite& writeFilter = WriteSkipDefault, bool bKeepPosition = false);
Expand Down
12 changes: 6 additions & 6 deletions src/EbmlElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ EbmlElement * EbmlElement::FindNextElement(IOCallback & DataStream, const EbmlSe
if (bFound) {
// find the element in the context and use the correct creator
const auto PossibleID = EbmlId(EbmlId::FromBuffer(PossibleIdNSize.data(), PossibleID_Length));
EbmlElement * Result = CreateElementUsingContext(PossibleID, Context, UpperLevel, false, SizeFound == SizeUnknown, AllowDummyElt, MaxLowerLevel);
EbmlElement * Result = CreateElementUsingContext(PossibleID, Context, UpperLevel, false, SizeFound, SizeFound == SizeUnknown, AllowDummyElt, MaxLowerLevel);
///< \todo continue is misplaced
if (Result != nullptr) {
if (AllowDummyElt || !Result->IsDummy()) {
Expand Down Expand Up @@ -413,15 +413,15 @@ EbmlElement * EbmlElement::SkipData(EbmlStream & DataStream, const EbmlSemanticC

EbmlElement *EbmlElement::CreateElementUsingContext(const EbmlId & aID, const EbmlSemanticContext & Context,
int & LowLevel, bool IsGlobalContext,
bool AsInfiniteSize,
std::uint64_t WithSize, bool AsInfiniteSize,
bool bAllowDummy, unsigned int MaxLowerLevel)
{
EbmlElement *Result = nullptr;

// elements at the current level
for (unsigned int ContextIndex = 0; ContextIndex < EBML_CTX_SIZE(Context); ContextIndex++) {
if (aID == EBML_CTX_IDX_ID(Context,ContextIndex)) {
if (AsInfiniteSize && !EBML_CTX_IDX_INFO(Context,ContextIndex).CanHaveInfiniteSize())
if (!EBML_CTX_IDX_INFO(Context,ContextIndex).IsSizeValid(WithSize, AsInfiniteSize))
return nullptr;
Result = &EBML_SEM_CREATE(EBML_CTX_IDX(Context,ContextIndex));
Result->SetSizeInfinite(AsInfiniteSize);
Expand All @@ -436,7 +436,7 @@ EbmlElement *EbmlElement::CreateElementUsingContext(const EbmlId & aID, const Eb
LowLevel--;
MaxLowerLevel--;
// recursive is good, but be carefull...
Result = CreateElementUsingContext(aID, tstContext, LowLevel, true, AsInfiniteSize, bAllowDummy, MaxLowerLevel);
Result = CreateElementUsingContext(aID, tstContext, LowLevel, true, WithSize, AsInfiniteSize, bAllowDummy, MaxLowerLevel);
if (Result != nullptr) {
return Result;
}
Expand All @@ -449,7 +449,7 @@ EbmlElement *EbmlElement::CreateElementUsingContext(const EbmlId & aID, const Eb
// parent elements
if (EBML_CTX_MASTER(Context) != nullptr && aID == EBML_INFO_ID(*EBML_CTX_MASTER(Context))) {
auto Callbacks = *EBML_CTX_MASTER(Context);
if (AsInfiniteSize && !Callbacks.CanHaveInfiniteSize())
if (!Callbacks.IsSizeValid(WithSize, AsInfiniteSize))
return nullptr;
LowLevel++; // already one level up (same as context)
Result = &EBML_INFO_CREATE(Callbacks);
Expand All @@ -461,7 +461,7 @@ EbmlElement *EbmlElement::CreateElementUsingContext(const EbmlId & aID, const Eb
if (EBML_CTX_PARENT(Context) != nullptr) {
LowLevel++;
MaxLowerLevel++;
return CreateElementUsingContext(aID, *EBML_CTX_PARENT(Context), LowLevel, IsGlobalContext, AsInfiniteSize, bAllowDummy, MaxLowerLevel);
return CreateElementUsingContext(aID, *EBML_CTX_PARENT(Context), LowLevel, IsGlobalContext, WithSize, AsInfiniteSize, bAllowDummy, MaxLowerLevel);
}

if (!IsGlobalContext && bAllowDummy && !AsInfiniteSize) {
Expand Down

0 comments on commit 8aa4cd3

Please sign in to comment.