aboutsummaryrefslogtreecommitdiff
path: root/zencore/compactbinarypackage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'zencore/compactbinarypackage.cpp')
-rw-r--r--zencore/compactbinarypackage.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/zencore/compactbinarypackage.cpp b/zencore/compactbinarypackage.cpp
index 6eaca5fdf..a25466bed 100644
--- a/zencore/compactbinarypackage.cpp
+++ b/zencore/compactbinarypackage.cpp
@@ -1279,6 +1279,48 @@ TEST_CASE("usonpackage.serialization")
}
}
+TEST_CASE("usonpackage.invalidpackage")
+{
+ const auto TestLoad = [](std::initializer_list<uint8_t> RawData, BufferAllocator Allocator = UniqueBuffer::Alloc) {
+ const MemoryView RawView = MakeMemoryView(RawData);
+ CbPackage FromArchive;
+ BinaryReader ReadAr(RawView);
+ CHECK_FALSE(FromArchive.TryLoad(ReadAr, Allocator));
+ };
+ const auto AllocFail = [](uint64_t) -> UniqueBuffer {
+ FAIL_CHECK("Allocation is not expected");
+ return UniqueBuffer();
+ };
+ SUBCASE("Empty") { TestLoad({}, AllocFail); }
+ SUBCASE("Invalid Initial Field")
+ {
+ TestLoad({uint8_t(CbFieldType::None)});
+ TestLoad({uint8_t(CbFieldType::Array)});
+ TestLoad({uint8_t(CbFieldType::UniformArray)});
+ TestLoad({uint8_t(CbFieldType::Binary)});
+ TestLoad({uint8_t(CbFieldType::String)});
+ TestLoad({uint8_t(CbFieldType::IntegerPositive)});
+ TestLoad({uint8_t(CbFieldType::IntegerNegative)});
+ TestLoad({uint8_t(CbFieldType::Float32)});
+ TestLoad({uint8_t(CbFieldType::Float64)});
+ TestLoad({uint8_t(CbFieldType::BoolFalse)});
+ TestLoad({uint8_t(CbFieldType::BoolTrue)});
+ TestLoad({uint8_t(CbFieldType::ObjectAttachment)});
+ TestLoad({uint8_t(CbFieldType::BinaryAttachment)});
+ TestLoad({uint8_t(CbFieldType::Uuid)});
+ TestLoad({uint8_t(CbFieldType::DateTime)});
+ TestLoad({uint8_t(CbFieldType::TimeSpan)});
+ TestLoad({uint8_t(CbFieldType::ObjectId)});
+ TestLoad({uint8_t(CbFieldType::CustomById)});
+ TestLoad({uint8_t(CbFieldType::CustomByName)});
+ }
+ SUBCASE("Size Out Of Bounds")
+ {
+ TestLoad({uint8_t(CbFieldType::Object), 1}, AllocFail);
+ TestLoad({uint8_t(CbFieldType::Object), 0xff, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0}, AllocFail);
+ }
+}
+
#endif
} // namespace zen