[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
Wed Dec 21 19:03:18 PST 2022
lkail updated this revision to Diff 484731.
lkail added a comment.
Herald added a subscriber: hiraditya.
Check if the offset of the first member is still in the buffer. Fixed asan errors.
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'
+# RUN: llvm-ar tv %p/Inputs/aix-empty-big-archive-with-freelist.a 2>&1 \
+# RUN: | not grep 'truncated or malformed archive'
Index: llvm/test/Object/archive-big-malformed-first-member.test
===================================================================
--- /dev/null
+++ llvm/test/Object/archive-big-malformed-first-member.test
@@ -0,0 +1,7 @@
+# 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'
Index: llvm/lib/Object/Archive.cpp
===================================================================
--- llvm/lib/Object/Archive.cpp
+++ llvm/lib/Object/Archive.cpp
@@ -949,7 +949,15 @@
return child_iterator::itr(
Child(this, FirstRegularData, FirstRegularStartOfFile), Err);
- const char *Loc = Data.getBufferStart() + getFirstChildOffset();
+ 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();
+ }
+
Child C(this, Loc, &Err);
if (Err)
return child_end();
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.484731.patch
Type: text/x-patch
Size: 2817 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221222/407b9340/attachment.bin>
More information about the llvm-commits
mailing list