diff options
Diffstat (limited to 'zenhttp/httpshared.cpp')
| -rw-r--r-- | zenhttp/httpshared.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/zenhttp/httpshared.cpp b/zenhttp/httpshared.cpp index f9aa3af82..a7dca5441 100644 --- a/zenhttp/httpshared.cpp +++ b/zenhttp/httpshared.cpp @@ -6,14 +6,14 @@ #include <zencore/compactbinarypackage.h> #include <zencore/compositebuffer.h> #include <zencore/filesystem.h> +#include <zencore/fmtutils.h> #include <zencore/iobuffer.h> #include <zencore/iohash.h> +#include <zencore/logging.h> #include <zencore/stream.h> #include <zencore/testing.h> #include <zencore/testutils.h> -#include <zencore/fmtutils.h> - #include <span> #include <vector> @@ -93,7 +93,10 @@ FormatPackageMessage(const CbPackage& Data, FormatFlags Flags) ResponseBuffers.push_back(std::move(RefBuffer)); }; - auto IsLocalRef = [](const CompositeBuffer& AttachmentBinary, CbAttachmentReferenceHeader& LocalRef, std::string& Path8) -> bool { + auto IsLocalRef = [](const CompositeBuffer& AttachmentBinary, + bool DenyPartialLocalReferences, + CbAttachmentReferenceHeader& LocalRef, + std::string& Path8) -> bool { const SharedBuffer& Segment = AttachmentBinary.GetSegments().front(); IoBufferFileReference Ref; const IoBuffer& SegmentBuffer = Segment.AsIoBuffer(); @@ -103,6 +106,11 @@ FormatPackageMessage(const CbPackage& Data, FormatFlags Flags) return false; } + if (DenyPartialLocalReferences && !SegmentBuffer.IsWholeFile()) + { + return false; + } + ExtendablePathBuilder<256> LocalRefFile; LocalRefFile.Append(std::filesystem::absolute(PathFromHandle(Ref.FileHandle))); Path8 = LocalRefFile.ToUtf8(); @@ -131,19 +139,20 @@ FormatPackageMessage(const CbPackage& Data, FormatFlags Flags) // segments to be marshaled at once bool MarshalByLocalRef = EnumHasAllFlags(Flags, FormatFlags::kAllowLocalReferences) && (Compressed.GetSegments().size() == 1); - + bool DenyPartialLocalReferences = EnumHasAllFlags(Flags, FormatFlags::kDenyPartialLocalReferences); CbAttachmentReferenceHeader LocalRef; std::string Path8; if (MarshalByLocalRef) { - MarshalByLocalRef = IsLocalRef(Compressed, LocalRef, Path8); + MarshalByLocalRef = IsLocalRef(Compressed, DenyPartialLocalReferences, LocalRef, Path8); } if (MarshalByLocalRef) { const bool IsCompressed = true; MarshalLocal(Path8, LocalRef, AttachmentHash, IsCompressed); + ZEN_DEBUG("Marshalled '{}' as file of {} bytes", Path8, Compressed.GetSize()); } else { @@ -171,19 +180,21 @@ FormatPackageMessage(const CbPackage& Data, FormatFlags Flags) IoHash AttachmentHash = IoHash::FromBLAKE3(AttachmentBuffer.GetRawHash()); bool MarshalByLocalRef = EnumHasAllFlags(Flags, FormatFlags::kAllowLocalReferences) && (AttachmentBinary.GetSegments().size() == 1); + bool DenyPartialLocalReferences = EnumHasAllFlags(Flags, FormatFlags::kDenyPartialLocalReferences); CbAttachmentReferenceHeader LocalRef; std::string Path8; if (MarshalByLocalRef) { - MarshalByLocalRef = IsLocalRef(AttachmentBinary, LocalRef, Path8); + MarshalByLocalRef = IsLocalRef(AttachmentBinary, DenyPartialLocalReferences, LocalRef, Path8); } if (MarshalByLocalRef) { const bool IsCompressed = false; MarshalLocal(Path8, LocalRef, AttachmentHash, IsCompressed); + ZEN_DEBUG("Marshalled '{}' as file of {} bytes", Path8, AttachmentBinary.GetSize()); } else { @@ -270,7 +281,7 @@ ParsePackageMessage(IoBuffer Payload, std::function<IoBuffer(const IoHash&, uint ZEN_ASSERT(AttachmentBuffer.Size() >= (sizeof(CbAttachmentReferenceHeader) + AttachRefHdr->AbsolutePathLength)); - std::filesystem::path Path{PathPointer}; + std::filesystem::path Path{std::u8string_view(PathPointer, AttachRefHdr->AbsolutePathLength)}; if (IoBuffer ChunkReference = IoBufferBuilder::MakeFromFile(Path, AttachRefHdr->PayloadByteOffset, AttachRefHdr->PayloadByteSize)) |