Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restrict the ranges of valid EBML ID values #298

Merged
merged 4 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ebml/EbmlDummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class EBML_DLL_API EbmlDummy : public EbmlBinary {
EbmlElement * Clone() const override { return new EbmlDummy(DummyId); }

static EbmlElement & Create() { return *(new EbmlDummy()); }
static const EbmlCallbacks ClassInfos;

private:
static const EbmlCallbacks ClassInfos;
const EbmlId DummyId;
static constexpr EbmlId DummyRawId{0xFF};
};
Expand Down
3 changes: 0 additions & 3 deletions ebml/EbmlElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,6 @@ class EBML_DLL_API EbmlDocVersion {
};

// functions for generic handling of data (should be static to all classes)
/*!
\todo Handle default value
*/
class EBML_DLL_API EbmlCallbacks {
public:
using CreateOperator = EbmlElement & (*)(void);
Expand Down
8 changes: 4 additions & 4 deletions ebml/EbmlId.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ class EBML_DLL_API EbmlId {
static constexpr bool IsValid(std::uint32_t Value)
{
if (Value < 0x100)
return Value >= 0x80;
return Value > 0x7F && Value < 0xFF;
if (Value < 0x10000)
return Value >= 0x4000;
return Value > 0x407E && Value < 0x7FFF;
if (Value < 0x1000000)
return Value >= 0x200000;
return Value >= 0x10000000;
return Value > 0x203FFE && Value < 0x3FFFFF;
return Value > 0x101FFFFE && Value < 0x1FFFFFFF;
}

static constexpr std::uint32_t FromBuffer(const binary aValue[4], const unsigned int aLength)
Expand Down
3 changes: 2 additions & 1 deletion src/EbmlDummy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace libebml {

static constexpr EbmlDocVersion AllEbmlVersions{"ebml"};

DEFINE_EBML_CLASS_ORPHAN(EbmlDummy, 0xFF, "DummyElement", AllEbmlVersions )
static constexpr const EbmlSemanticContext Context_EbmlDummy = EbmlSemanticContext(nullptr, GetEbmlGlobal_Context, nullptr);
constexpr const EbmlCallbacks EbmlDummy::ClassInfos(EbmlDummy::Create, EbmlDummy::DummyRawId, false, false, "DummyElement", Context_EbmlDummy, AllEbmlVersions);

EbmlDummy::EbmlDummy(const EbmlId & aId) : EbmlBinary(EbmlDummy::ClassInfos), DummyId(aId) {}

Expand Down
4 changes: 2 additions & 2 deletions test/test_macros.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ DEFINE_xxx_UNISTRING(UniStringWithoutDefault, 0x4123, EbmlHead, "UniStringWithou
DECLARE_EBML_UINTEGER_DEF(UIntWithDefault)
EBML_CONCRETE_CLASS(UIntWithDefault)
};
DEFINE_EBML_UINTEGER_DEF(UIntWithDefault, 0x654321, EbmlHead, "UIntWithDefault", 42, AllVersions)
DEFINE_EBML_UINTEGER_DEF(UIntWithDefault, 0x354321, EbmlHead, "UIntWithDefault", 42, AllVersions)

DECLARE_xxx_UINTEGER(UIntWithoutDefault,)
EBML_CONCRETE_CLASS(UIntWithoutDefault)
};
DEFINE_xxx_UINTEGER(UIntWithoutDefault, 0x612345, EbmlHead, "UIntWithoutDefault", AllVersions, GetEbmlGlobal_Context)
DEFINE_xxx_UINTEGER(UIntWithoutDefault, 0x312345, EbmlHead, "UIntWithoutDefault", AllVersions, GetEbmlGlobal_Context)

int main(void)
{
Expand Down