aboutsummaryrefslogtreecommitdiff
path: root/zencore/compactbinarypackage.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-09-19 10:02:56 +0200
committerGitHub <[email protected]>2022-09-19 01:02:56 -0700
commit14fe7d17060b2e12203ed4b1fbfe44dd5aa606ec (patch)
treeeaab0f00aa2c4aeb88d9d96be91c7e7eb6d6f775 /zencore/compactbinarypackage.cpp
parent0.1.6-pre8 (diff)
downloadzen-14fe7d17060b2e12203ed4b1fbfe44dd5aa606ec.tar.xz
zen-14fe7d17060b2e12203ed4b1fbfe44dd5aa606ec.zip
LoadCompactBinary gracefully handles read failures and sizes larger than the archive (#165)
* add failing test * CompactBinary: Fixed LoadCompactBinary to gracefully handle read failures and sizes larger than the archive From https://p4-swarm.epicgames.net/changes/21983905 * changelog
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