[llvm] 09a3aef - Revert "[AIX][BigArchive] Treat the archive is empty if the first child member offset is zero"

Mitch Phillips via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 30 09:42:32 PST 2023


Author: Mitch Phillips
Date: 2023-01-30T09:41:55-08:00
New Revision: 09a3aef0f8f4ef7789713b6edb185f4541858aac

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

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

This reverts commit 7f0003c19c3a47f484ea9cc929728808b27ace32.

Reason: This broke the ASan buildbot, see the comments in
https://reviews.llvm.org/D138986 for more information.

Added: 
    

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

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


################################################################################
diff  --git a/llvm/include/llvm/Object/Archive.h b/llvm/include/llvm/Object/Archive.h
index b77c8537eeaa0..fbacee964aa88 100644
--- a/llvm/include/llvm/Object/Archive.h
+++ b/llvm/include/llvm/Object/Archive.h
@@ -410,7 +410,9 @@ 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 getFirstChildOffset() == 0; }
+  bool isEmpty() const override {
+    return Data.getBufferSize() == sizeof(FixLenHdr);
+  };
 };
 
 } // end namespace object

diff  --git a/llvm/lib/Object/Archive.cpp b/llvm/lib/Object/Archive.cpp
index 046bcb3ff8816..2cf9241238882 100644
--- a/llvm/lib/Object/Archive.cpp
+++ b/llvm/lib/Object/Archive.cpp
@@ -949,15 +949,7 @@ Archive::child_iterator Archive::child_begin(Error &Err,
     return child_iterator::itr(
         Child(this, FirstRegularData, FirstRegularStartOfFile), Err);
 
-  uint64_t FirstChildOffset = getFirstChildOffset();
-  const char *Loc = Data.getBufferStart() + FirstChildOffset;
-  if (Loc >= Data.getBufferEnd()) {
-    Err = malformedError("First member offset " + Twine(FirstChildOffset) +
-                         " is beyond the data buffer which has size of " +
-                         Twine(Data.getBufferSize()));
-    return child_end();
-  }
-
+  const char *Loc = Data.getBufferStart() + getFirstChildOffset();
   Child C(this, Loc, &Err);
   if (Err)
     return child_end();

diff  --git a/llvm/test/Object/archive-big-malformed-first-member.test b/llvm/test/Object/archive-big-malformed-first-member.test
deleted file mode 100644
index 08ae37b47816c..0000000000000
--- a/llvm/test/Object/archive-big-malformed-first-member.test
+++ /dev/null
@@ -1,7 +0,0 @@
-# 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'
-# 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 | 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 05e45ca51c39e..2ac3253446597 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: llvm-ar tv %p/Inputs/aix-empty-big-archive-with-freelist.a 2>&1 \
-# RUN:   | not grep 'truncated or malformed archive'
+# RUN: not llvm-ar tv %p/Inputs/aix-empty-big-archive-with-freelist.a 2>&1 \
+# RUN:   | grep 'truncated or malformed archive'


        


More information about the llvm-commits mailing list