[PATCH] D150462: [NFC] Fixed malformed big archive when member file size large than 4Gbytes

Digger Lin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 12 10:34:14 PDT 2023


DiggerLin created this revision.
DiggerLin added reviewers: stephenpeckham, daltenty, jhenderson.
Herald added a subscriber: hiraditya.
Herald added a project: All.
DiggerLin requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

1. we use the unsigned type for NextOffset,PrevOffset ,GlobalSymbolOffset , MemberTableSize, it will caused a malform big archive when the member file size large than 4G.
2. also fix a NFC comment on https://reviews.llvm.org/D142479#inline-1443927


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150462

Files:
  llvm/lib/Object/ArchiveWriter.cpp


Index: llvm/lib/Object/ArchiveWriter.cpp
===================================================================
--- llvm/lib/Object/ArchiveWriter.cpp
+++ llvm/lib/Object/ArchiveWriter.cpp
@@ -252,8 +252,8 @@
 printBigArchiveMemberHeader(raw_ostream &Out, StringRef Name,
                             const sys::TimePoint<std::chrono::seconds> &ModTime,
                             unsigned UID, unsigned GID, unsigned Perms,
-                            uint64_t Size, unsigned PrevOffset,
-                            unsigned NextOffset) {
+                            uint64_t Size, uint64_t PrevOffset,
+                            uint64_t NextOffset) {
   unsigned NameLen = Name.size();
 
   printWithSpacePadding(Out, Size, 20);           // File member size
@@ -704,7 +704,8 @@
 
   // The big archive format needs to know the offset of the previous member
   // header.
-  unsigned PrevOffset = 0, Index = 0;
+  uint64_t PrevOffset = 0;
+  uint16_t Index = 0;
   for (const NewArchiveMember &M : NewMembers) {
     std::string Header;
     raw_string_ostream Out(Header);
@@ -740,7 +741,7 @@
     }
 
     if (isAIXBigArchive(Kind)) {
-      unsigned NextOffset = Pos + sizeof(object::BigArMemHdrType) +
+      uint64_t NextOffset = Pos + sizeof(object::BigArMemHdrType) +
                             alignTo(M.MemberName.size(), 2) + alignTo(Size, 2);
       printBigArchiveMemberHeader(Out, M.MemberName, ModTime, M.UID, M.GID,
                                   M.Perms, Size, PrevOffset, NextOffset);
@@ -948,11 +949,11 @@
     }
 
     // AIX member table size.
-    unsigned MemberTableSize = 20 + // Number of members field
+    uint64_t MemberTableSize = 20 + // Number of members field
                                20 * MemberOffsets.size() +
                                MemberTableNameStrTblSize;
 
-    unsigned GlobalSymbolOffset =
+    uint64_t GlobalSymbolOffset =
         (WriteSymtab && NumSyms > 0)
             ? LastMemberEndOffset +
                   alignTo(sizeof(object::BigArMemHdrType) + MemberTableSize, 2)
@@ -963,7 +964,7 @@
                           20); // Offset to member table
     // If there are no file members in the archive, there will be no global
     // symbol table.
-    printWithSpacePadding(Out, NewMembers.size() ? GlobalSymbolOffset : 0, 20);
+    printWithSpacePadding(Out, GlobalSymbolOffset, 20);
     printWithSpacePadding(
         Out, 0,
         20); // Offset to 64 bits global symbol table - Not supported yet


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150462.521705.patch
Type: text/x-patch
Size: 2486 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230512/a4a89d4f/attachment.bin>


More information about the llvm-commits mailing list