aboutsummaryrefslogtreecommitdiff
path: root/zencore/compactbinarypackage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'zencore/compactbinarypackage.cpp')
-rw-r--r--zencore/compactbinarypackage.cpp46
1 files changed, 40 insertions, 6 deletions
diff --git a/zencore/compactbinarypackage.cpp b/zencore/compactbinarypackage.cpp
index 88757d47f..f7ce371c8 100644
--- a/zencore/compactbinarypackage.cpp
+++ b/zencore/compactbinarypackage.cpp
@@ -635,6 +635,11 @@ namespace legacy {
Writer.AddBinary(Attachment.AsBinary());
Writer.AddBinaryAttachment(Attachment.GetHash());
}
+ else if (Attachment.IsCompressedBinary())
+ {
+ Writer.AddBinary(Attachment.AsCompressedBinary().GetCompressed());
+ Writer.AddBinaryAttachment(Attachment.GetHash());
+ }
else if (Attachment.IsNull())
{
Writer.AddBinary(MemoryView());
@@ -695,17 +700,32 @@ namespace legacy {
SharedBuffer Buffer = SharedBuffer::MakeView(View, ValueField.GetOuterBuffer()).MakeOwned();
CbField HashField = LoadCompactBinary(Reader, Allocator);
const IoHash& Hash = HashField.AsAttachment();
- if (HashField.HasError() || IoHash::HashBuffer(Buffer) != Hash)
+ if (HashField.HasError())
{
return false;
}
- if (HashField.IsObjectAttachment())
+ if (CompressedBuffer Compressed = CompressedBuffer::FromCompressed(Buffer))
{
- Package.AddAttachment(CbAttachment(CbObject(std::move(Buffer)), Hash));
+ if (IoHash::FromBLAKE3(Compressed.GetRawHash()) != Hash)
+ {
+ return false;
+ }
+ Package.AddAttachment(CbAttachment(Compressed));
}
else
{
- Package.AddAttachment(CbAttachment(CompositeBuffer(std::move(Buffer)), Hash));
+ if (IoHash::HashBuffer(Buffer) != Hash)
+ {
+ return false;
+ }
+ if (HashField.IsObjectAttachment())
+ {
+ Package.AddAttachment(CbAttachment(CbObject(std::move(Buffer)), Hash));
+ }
+ else
+ {
+ Package.AddAttachment(CbAttachment(CompositeBuffer(std::move(Buffer)), Hash));
+ }
}
}
}
@@ -714,8 +734,22 @@ namespace legacy {
const IoHash Hash = ValueField.AsHash();
ZEN_ASSERT(Mapper);
-
- Package.AddAttachment(CbAttachment((*Mapper)(Hash), Hash));
+ if (SharedBuffer AttachmentData = (*Mapper)(Hash))
+ {
+ if (CompressedBuffer Compressed = CompressedBuffer::FromCompressed(AttachmentData))
+ {
+ Package.AddAttachment(CbAttachment(Compressed));
+ }
+ else
+ {
+ const CbValidateError ValidationResult = ValidateCompactBinary(AttachmentData.GetView(), CbValidateMode::All);
+ if (ValidationResult != CbValidateError::None)
+ {
+ return false;
+ }
+ Package.AddAttachment(CbAttachment(CbObject(std::move(AttachmentData)), Hash));
+ }
+ }
}
else
{