aboutsummaryrefslogtreecommitdiff
path: root/src/zenutil
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2024-05-02 17:40:30 +0200
committerGitHub Enterprise <[email protected]>2024-05-02 17:40:30 +0200
commit1155ed2048a24f4dfcfa65d63243b77973f820d6 (patch)
tree49961435a57e3a516506bb6965d021c4864e3ecb /src/zenutil
parentuse write and move in place for safer writing of files (#70) (diff)
downloadzen-1155ed2048a24f4dfcfa65d63243b77973f820d6.tar.xz
zen-1155ed2048a24f4dfcfa65d63243b77973f820d6.zip
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
Diffstat (limited to 'src/zenutil')
-rw-r--r--src/zenutil/packageformat.cpp12
1 files changed, 12 insertions, 0 deletions
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<IoBuffer> Result = FormatPackageMessage(Pkg, nullptr);
+}
+
TEST_CASE("CbPackage.LocalRef")
{
ScopedTemporaryDirectory TempDir;