Skip to content

Commit 7f0003c

Browse files
author
Kai Luo
committed
[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
1 parent 28f9bfe commit 7f0003c

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

llvm/include/llvm/Object/Archive.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,7 @@ class BigArchive : public Archive {
410410
BigArchive(MemoryBufferRef Source, Error &Err);
411411
uint64_t getFirstChildOffset() const override { return FirstChildOffset; }
412412
uint64_t getLastChildOffset() const { return LastChildOffset; }
413-
bool isEmpty() const override {
414-
return Data.getBufferSize() == sizeof(FixLenHdr);
415-
};
413+
bool isEmpty() const override { return getFirstChildOffset() == 0; }
416414
};
417415

418416
} // end namespace object

llvm/lib/Object/Archive.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,15 @@ Archive::child_iterator Archive::child_begin(Error &Err,
949949
return child_iterator::itr(
950950
Child(this, FirstRegularData, FirstRegularStartOfFile), Err);
951951

952-
const char *Loc = Data.getBufferStart() + getFirstChildOffset();
952+
uint64_t FirstChildOffset = getFirstChildOffset();
953+
const char *Loc = Data.getBufferStart() + FirstChildOffset;
954+
if (Loc >= Data.getBufferEnd()) {
955+
Err = malformedError("First member offset " + Twine(FirstChildOffset) +
956+
" is beyond the data buffer which has size of " +
957+
Twine(Data.getBufferSize()));
958+
return child_end();
959+
}
960+
953961
Child C(this, Loc, &Err);
954962
if (Err)
955963
return child_end();
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Test reading an empty archive with first member's offset is not zero.
2+
# RUN: echo "<bigaf>" > %t.a
3+
# RUN: echo -n "0 0 0 128 0 0 " >> %t.a
4+
# RUN: not llvm-ar tv %t.a 2>&1 | grep 'truncated or malformed archive'
5+
# RUN: echo "<bigaf>" > %t.a
6+
# RUN: echo -n "0 0 0 28 0 0 " >> %t.a
7+
# RUN: not llvm-ar tv %t.a 2>&1 | grep 'truncated or malformed archive'
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Test reading an empty archive with free list in it.
2-
# RUN: not llvm-ar tv %p/Inputs/aix-empty-big-archive-with-freelist.a 2>&1 \
3-
# RUN: | grep 'truncated or malformed archive'
2+
# RUN: llvm-ar tv %p/Inputs/aix-empty-big-archive-with-freelist.a 2>&1 \
3+
# RUN: | not grep 'truncated or malformed archive'

0 commit comments

Comments
 (0)