[llvm] b26fe2a - [AIX][BigArchive] Treat the archive is empty if the first child member offset is zero

Kai Luo via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 18 21:18:54 PST 2022


Author: Kai Luo
Date: 2022-12-19T13:18:46+08:00
New Revision: b26fe2a3e520a520e785dc6b4e5758b7fde6af9d

URL: https://github.com/llvm/llvm-project/commit/b26fe2a3e520a520e785dc6b4e5758b7fde6af9d
DIFF: https://github.com/llvm/llvm-project/commit/b26fe2a3e520a520e785dc6b4e5758b7fde6af9d.diff

LOG: [AIX][BigArchive] Treat the archive is empty if the first child member offset is zero

If the archive contains free list and contains no member file, the buffer length doesn't equal to length of the header.

Reviewed By: Esme, DiggerLin, #powerpc

Differential Revision: https://reviews.llvm.org/D138986

Added: 
    llvm/test/Object/archive-big-malformed-first-member.test

Modified: 
    llvm/include/llvm/Object/Archive.h
    llvm/test/Object/archive-big-read-empty-with-freelist.test

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Object/Archive.h b/llvm/include/llvm/Object/Archive.h
index f5b9fca2816df..56019ee8b8cb5 100644
--- a/llvm/include/llvm/Object/Archive.h
+++ b/llvm/include/llvm/Object/Archive.h
@@ -413,9 +413,7 @@ class BigArchive : public Archive {
   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

diff  --git a/llvm/test/Object/archive-big-malformed-first-member.test b/llvm/test/Object/archive-big-malformed-first-member.test
new file mode 100644
index 0000000000000..9107bdb6d9d20
--- /dev/null
+++ b/llvm/test/Object/archive-big-malformed-first-member.test
@@ -0,0 +1,4 @@
+# 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 | grep 'truncated or malformed archive'

diff  --git a/llvm/test/Object/archive-big-read-empty-with-freelist.test b/llvm/test/Object/archive-big-read-empty-with-freelist.test
index 2ac3253446597..05e45ca51c39e 100644
--- a/llvm/test/Object/archive-big-read-empty-with-freelist.test
+++ b/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'
+# RUN: llvm-ar tv %p/Inputs/aix-empty-big-archive-with-freelist.a 2>&1 \
+# RUN:   | not grep 'truncated or malformed archive'


        


More information about the llvm-commits mailing list