================
@@ -197,11 +176,53 @@ Error extractFromArchive(const Archive &Library,
return Error::success();
}
+bool isCompressed(const OffloadBinary::Header &Header) {
+ return Header.Version >= 3 && Header.InflatedSize != 0;
+}
+
+Expected<std::unique_ptr<MemoryBuffer>>
+decompressOffloadBinary(MemoryBufferRef Buf) {
+ const auto *Header =
+ reinterpret_cast<const OffloadBinary::Header *>(Buf.getBufferStart());
+ if (Header->EntriesOffset != sizeof(OffloadBinary::Header) ||
+ Header->EntriesOffset > Header->Size ||
+ Header->InflatedSize < Header->EntriesOffset)
+ return errorCodeToError(object_error::unexpected_eof);
+
+ // Get the compressed binary blob after the header.
+ StringRef Compressed = Buf.getBuffer()
+ .take_front(Header->Size)
+ .drop_front(Header->EntriesOffset);
+ uint64_t BodySize = Header->InflatedSize - Header->EntriesOffset;
+
+ ArrayRef<uint8_t> CompressedBytes = arrayRefFromStringRef(Compressed);
+ if (const char *Reason =
compression::getReasonIfUnsupported(CompressedBytes))
+ return createStringError(Reason);
----------------
jh7370 wrote:
Looks like this is redundant, since `decompress` does the check internally and
feeds it into the returned error?
https://github.com/llvm/llvm-project/pull/222774
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits