From 1155ed2048a24f4dfcfa65d63243b77973f820d6 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Thu, 2 May 2024 17:40:30 +0200 Subject: fix zero size attachment replies (#69) - Bugfix: Don't try to respond with zero size partial cache value when partial size is zero - Improvement: Added more validation of data read from cache / cas --- src/zenutil/packageformat.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/zenutil/packageformat.cpp') diff --git a/src/zenutil/packageformat.cpp b/src/zenutil/packageformat.cpp index 2512351f5..963a442cd 100644 --- a/src/zenutil/packageformat.cpp +++ b/src/zenutil/packageformat.cpp @@ -51,6 +51,7 @@ FormatPackageMessageBuffer(const CbPackage& Data, FormatFlags Flags, void* Targe for (IoBuffer& Buf : Message) { + ZEN_ASSERT(Buf.GetSize() > 0); Buffers.push_back(SharedBuffer(Buf)); } @@ -200,6 +201,7 @@ FormatPackageMessage(const CbPackage& Data, FormatFlags Flags, void* TargetProce // Root object IoBuffer RootIoBuffer = Data.GetObject().GetBuffer().AsIoBuffer(); + ZEN_ASSERT(RootIoBuffer.GetSize() > 0); ResponseBuffers.push_back(RootIoBuffer); // Root object *AttachmentInfo++ = {.PayloadSize = RootIoBuffer.Size(), .Flags = CbAttachmentEntry::kIsObject, .AttachmentHash = Data.GetObjectHash()}; @@ -257,6 +259,7 @@ FormatPackageMessage(const CbPackage& Data, FormatFlags Flags, void* TargetProce for (const SharedBuffer& Segment : Compressed.GetSegments()) { + ZEN_ASSERT(Segment.GetSize() > 0); ResponseBuffers.push_back(Segment.AsIoBuffer()); } } @@ -264,6 +267,7 @@ FormatPackageMessage(const CbPackage& Data, FormatFlags Flags, void* TargetProce else if (CbObject AttachmentObject = Attachment.AsObject()) { IoBuffer ObjIoBuffer = AttachmentObject.GetBuffer().AsIoBuffer(); + ZEN_ASSERT(ObjIoBuffer.GetSize() > 0); ResponseBuffers.push_back(ObjIoBuffer); *AttachmentInfo++ = {.PayloadSize = ObjIoBuffer.Size(), @@ -307,6 +311,7 @@ FormatPackageMessage(const CbPackage& Data, FormatFlags Flags, void* TargetProce for (const SharedBuffer& Segment : AttachmentBinary.GetSegments()) { + ZEN_ASSERT(Segment.GetSize() > 0); ResponseBuffers.push_back(Segment.AsIoBuffer()); } } @@ -808,6 +813,13 @@ TEST_CASE("CbPackage.Serialization") Reader.Finalize(); } +TEST_CASE("CbPackage.EmptyObject") +{ + CbPackage Pkg; + Pkg.SetObject({}); + std::vector Result = FormatPackageMessage(Pkg, nullptr); +} + TEST_CASE("CbPackage.LocalRef") { ScopedTemporaryDirectory TempDir; -- cgit v1.2.3