[PATCH] D138986: [AIX][BigArchive] Treat the archive is empty if the first child member offset is zero
Kai Luo via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 31 06:32:27 PST 2023
lkail updated this revision to Diff 493589.
lkail added a comment.
Complete error messages.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D138986/new/
https://reviews.llvm.org/D138986
Files:
llvm/include/llvm/Object/Archive.h
llvm/lib/Object/Archive.cpp
llvm/test/Object/archive-big-malformed-first-member.test
llvm/test/Object/archive-big-read-empty-with-freelist.test
Index: llvm/test/Object/archive-big-read-empty-with-freelist.test
===================================================================
--- llvm/test/Object/archive-big-read-empty-with-freelist.test
+++ llvm/test/Object/archive-big-read-empty-with-freelist.test
@@ -1,3 +1,3 @@
-# Test reading an empty archive with free list in it.
-# RUN: not llvm-ar tv %p/Inputs/aix-empty-big-archive-with-freelist.a 2>&1 \
-# RUN: | grep 'truncated or malformed archive'
+## Test reading an empty archive with free list in it, should exit normally.
+# RUN: llvm-ar tv %p/Inputs/aix-empty-big-archive-with-freelist.a 2>&1 \
+# RUN: | count 0
Index: llvm/test/Object/archive-big-malformed-first-member.test
===================================================================
--- /dev/null
+++ llvm/test/Object/archive-big-malformed-first-member.test
@@ -0,0 +1,15 @@
+## Test reading an archive with malformed header.
+# RUN: echo "<bigaf>" > %t.a
+# RUN: not llvm-ar tv %t.a 2>&1 | FileCheck --check-prefix=CHECK-HEADER %s
+# CHECK-HEADER: truncated or malformed archive{{.*}}malformed AIX big archive: incomplete fixed length header
+
+## Test reading an empty archive with first member's offset is not zero.
+# RUN: echo "<bigaf>" > %t.a
+# RUN: echo -n "0 0 0 128 0 0 " >> %t.a
+# RUN: not llvm-ar tv %t.a 2>&1 | FileCheck %s
+
+# RUN: echo "<bigaf>" > %t.a
+# RUN: echo -n "0 0 0 28 0 0 " >> %t.a
+# RUN: not llvm-ar tv %t.a 2>&1 | FileCheck %s
+
+# CHECK: truncated or malformed archive{{.*}}malformed AIX big archive: remaining buffer is unable to contain next archive member
Index: llvm/lib/Object/Archive.cpp
===================================================================
--- llvm/lib/Object/Archive.cpp
+++ llvm/lib/Object/Archive.cpp
@@ -135,6 +135,13 @@
return;
ErrorAsOutParameter ErrAsOutParam(Err);
+ if (RawHeaderPtr + getSizeOf() >= Parent->getData().end()) {
+ if (Err)
+ *Err = malformedError("malformed AIX big archive: remaining buffer is "
+ "unable to contain next archive member");
+ return;
+ }
+
if (Size < getSizeOf()) {
Error SubErr = createMemberHeaderParseError(this, RawHeaderPtr, Size);
if (Err)
@@ -1172,6 +1179,14 @@
ErrorAsOutParameter ErrAsOutParam(&Err);
StringRef Buffer = Data.getBuffer();
ArFixLenHdr = reinterpret_cast<const FixLenHdr *>(Buffer.data());
+ uint64_t BufferSize = Data.getBufferSize();
+
+ if (BufferSize < sizeof(FixLenHdr)) {
+ Err = malformedError("malformed AIX big archive: incomplete fixed length "
+ "header, the archive is only" +
+ Twine(BufferSize) + " byte(s)");
+ return;
+ }
StringRef RawOffset = getFieldRawString(ArFixLenHdr->FirstChildOffset);
if (RawOffset.getAsInteger(10, FirstChildOffset))
@@ -1198,7 +1213,6 @@
return;
if (GlobSymOffset > 0) {
- uint64_t BufferSize = Data.getBufferSize();
uint64_t GlobalSymTblContentOffset =
GlobSymOffset + sizeof(BigArMemHdrType);
if (GlobalSymTblContentOffset > BufferSize) {
Index: llvm/include/llvm/Object/Archive.h
===================================================================
--- llvm/include/llvm/Object/Archive.h
+++ llvm/include/llvm/Object/Archive.h
@@ -410,9 +410,7 @@
BigArchive(MemoryBufferRef Source, Error &Err);
uint64_t getFirstChildOffset() const override { return FirstChildOffset; }
uint64_t getLastChildOffset() const { return LastChildOffset; }
- bool isEmpty() const override {
- return Data.getBufferSize() == sizeof(FixLenHdr);
- };
+ bool isEmpty() const override { return getFirstChildOffset() == 0; }
};
} // end namespace object
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138986.493589.patch
Type: text/x-patch
Size: 3879 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230131/6291e5f6/attachment.bin>
More information about the llvm-commits
mailing list