From: Kai Luo Date: Mon, 19 Dec 2022 05:01:55 +0000 (+0800) Subject: [AIX][BigArchive] Treat the archive is empty if the first child member offset is... X-Git-Tag: upstream/17.0.6~23312 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b26fe2a3e520a520e785dc6b4e5758b7fde6af9d;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/llvm/include/llvm/Object/Archive.h b/llvm/include/llvm/Object/Archive.h index f5b9fca..56019ee 100644 --- a/llvm/include/llvm/Object/Archive.h +++ b/llvm/include/llvm/Object/Archive.h @@ -413,9 +413,7 @@ public: 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 0000000..9107bdb --- /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 "" > %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 2ac3253..05e45ca 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'