aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/compress.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2025-11-26 13:04:38 +0100
committerGitHub Enterprise <[email protected]>2025-11-26 13:04:38 +0100
commitb5ad9fb4c7475b4f4516bf401a7bb2cc2f20b3ee (patch)
treeb84003069c9a10c5be5773dc7c05f8961eda3cb1 /src/zencore/compress.cpp
parentremove 'auto' option for zen builds download (#665) (diff)
downloadzen-b5ad9fb4c7475b4f4516bf401a7bb2cc2f20b3ee.tar.xz
zen-b5ad9fb4c7475b4f4516bf401a7bb2cc2f20b3ee.zip
RawOffset can be anything and we expect an empty buffer to be returned along with RawSize = 0 if the offset was out of bounds for the value. (#666)
Diffstat (limited to 'src/zencore/compress.cpp')
-rw-r--r--src/zencore/compress.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/zencore/compress.cpp b/src/zencore/compress.cpp
index d9f381811..84af83119 100644
--- a/src/zencore/compress.cpp
+++ b/src/zencore/compress.cpp
@@ -1995,8 +1995,15 @@ CompressedBuffer::CopyRange(uint64_t RawOffset, uint64_t RawSize) const
UniqueBuffer RawHeaderData;
if (ReadHeader(CompressedData, Header, &RawHeaderData))
{
- const uint64_t TotalRawSize = RawSize < ~uint64_t(0) ? RawSize : Header.TotalRawSize - RawOffset;
- Range.CompressedData = CopyCompressedRange(Header, RawHeaderData.GetView(), CompressedData, RawOffset, TotalRawSize);
+ if (RawOffset < Header.TotalRawSize)
+ {
+ const uint64_t MaxRawSize = RawOffset == ~uint64_t(0) ? Header.TotalRawSize : Header.TotalRawSize - RawOffset;
+ const uint64_t TotalRawSize = RawSize == ~uint64_t(0) ? MaxRawSize : Min(RawSize, MaxRawSize);
+ if (TotalRawSize > 0)
+ {
+ Range.CompressedData = CopyCompressedRange(Header, RawHeaderData.GetView(), CompressedData, RawOffset, TotalRawSize);
+ }
+ }
}
}
return Range;
@@ -2012,8 +2019,16 @@ CompressedBuffer::GetRange(uint64_t RawOffset, uint64_t RawSize) const
UniqueBuffer RawHeaderData;
if (ReadHeader(CompressedData, Header, &RawHeaderData))
{
- const uint64_t TotalRawSize = RawSize < ~uint64_t(0) ? RawSize : Header.TotalRawSize - RawOffset;
- Range.CompressedData = GetCompressedRange(Header, RawHeaderData.GetView(), CompressedData, RawOffset, TotalRawSize);
+ if (RawOffset < Header.TotalRawSize)
+ {
+ const uint64_t MaxRawSize = RawOffset == ~uint64_t(0) ? Header.TotalRawSize : Header.TotalRawSize - RawOffset;
+ const uint64_t TotalRawSize = RawSize == ~uint64_t(0) ? MaxRawSize : Min(RawSize, MaxRawSize);
+
+ if (TotalRawSize > 0)
+ {
+ Range.CompressedData = GetCompressedRange(Header, RawHeaderData.GetView(), CompressedData, RawOffset, TotalRawSize);
+ }
+ }
}
}
return Range;