From d88262efac17b956600c85a2ba5e70c66937eb96 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Fri, 20 Aug 2021 13:51:39 +0200 Subject: CL16570338: CompactBinary: Added validation to LoadCompactBinary and removed asserts from the other load functions --- zencore/compactbinary.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'zencore/compactbinary.cpp') diff --git a/zencore/compactbinary.cpp b/zencore/compactbinary.cpp index 62c60418c..73ca9832f 100644 --- a/zencore/compactbinary.cpp +++ b/zencore/compactbinary.cpp @@ -2,6 +2,7 @@ #include "zencore/compactbinary.h" +#include "zencore/compactbinaryvalidation.h" #include #include #include @@ -1072,7 +1073,10 @@ LoadCompactBinary(BinaryReader& Ar, BufferAllocator Allocator) { break; } - ZEN_ASSERT(FieldSize > 0, "Failed to load from invalid compact binary data."); + if (FieldSize == 0) + { + return CbField(); + } } // Allocate the buffer, copy the header, and read the remainder of the field. @@ -1085,6 +1089,10 @@ LoadCompactBinary(BinaryReader& Ar, BufferAllocator Allocator) { Ar.Read(View.GetData(), View.GetSize()); } + if (ValidateCompactBinary(Buffer, CbValidateMode::Default) != CbValidateError::None) + { + return CbField(); + } return CbField(SharedBuffer(std::move(Buffer))); } -- cgit v1.2.3