From 062054e5caa88d31ff93a21bf418d1e8d232cce3 Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Mon, 12 Oct 2015 22:04:54 +0000 Subject: [PATCH] =?utf8?q?Fixed=20bugs=20in=20llvm-obdump=20while=20parsin?= =?utf8?q?g=20Mach-O=20files=20from=20malformed=20archives=20that=20caused?= =?utf8?q?=20aborts.=20=20This=20was=20because=20of=20the=20characters=20o?= =?utf8?q?f=20the=20=E2=80=98Size=E2=80=99=20field=20in=20the=20archive=20?= =?utf8?q?header=20did=20not=20contain=20decimal=20characters.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit rdar://22983603 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250117 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/Archive.h | 1 + lib/Object/Archive.cpp | 12 ++++++++++++ .../X86/Inputs/malformed-machos/00000031.a | Bin 0 -> 2768 bytes .../tools/llvm-objdump/X86/malformed-machos.test | 6 ++++++ 4 files changed, 19 insertions(+) create mode 100644 test/tools/llvm-objdump/X86/Inputs/malformed-machos/00000031.a diff --git a/include/llvm/Object/Archive.h b/include/llvm/Object/Archive.h index d7f46551827..5271dde5721 100644 --- a/include/llvm/Object/Archive.h +++ b/include/llvm/Object/Archive.h @@ -38,6 +38,7 @@ struct ArchiveMemberHeader { /// Members are not larger than 4GB. uint32_t getSize() const; + bool isSizeValid() const; sys::fs::perms getAccessMode() const; sys::TimeValue getLastModified() const; diff --git a/lib/Object/Archive.cpp b/lib/Object/Archive.cpp index 42fec39851d..b0e0881c789 100644 --- a/lib/Object/Archive.cpp +++ b/lib/Object/Archive.cpp @@ -50,6 +50,13 @@ uint32_t ArchiveMemberHeader::getSize() const { return Ret; } +bool ArchiveMemberHeader::isSizeValid() const { + uint32_t Ret; + if (llvm::StringRef(Size, sizeof(Size)).rtrim(" ").getAsInteger(10, Ret)) + return false; + return true; +} + sys::fs::perms ArchiveMemberHeader::getAccessMode() const { unsigned Ret; if (StringRef(AccessMode, sizeof(AccessMode)).rtrim(" ").getAsInteger(8, Ret)) @@ -89,6 +96,11 @@ Archive::Child::Child(const Archive *Parent, const char *Start) uint64_t Size = sizeof(ArchiveMemberHeader); Data = StringRef(Start, Size); + // Check to make sure the size is valid. + const ArchiveMemberHeader *Header = + reinterpret_cast(Data.data()); + if (!Header->isSizeValid()) + return; if (!isThinMember()) { Size += getRawSize(); Data = StringRef(Start, Size); diff --git a/test/tools/llvm-objdump/X86/Inputs/malformed-machos/00000031.a b/test/tools/llvm-objdump/X86/Inputs/malformed-machos/00000031.a new file mode 100644 index 0000000000000000000000000000000000000000..b784d8163f54f0d06633bf372aff80258e421507 GIT binary patch literal 2768 zcmd5-O-NKx6u$nYjSWHy^9e3m2oYfe zA+21htI&dWrHc?GqR48~&P4?SwUFGjs6hM9efN%&j;4mxfqTF6bMKkC=YIFRSIaZc z7-PvvjHLrpFf5FvjRBJ}gfHzKd@xyZL4{B2=&mvyww||gVGgh0!OmbnTOVr(`~1zmuJwV|fYu)jhg`ZA3?Z!c>po5A81BQ5 zKsG$5Bk?&M4p|kisl&)u5;jut`R$LzWfV1u3XPics(z-3LK9>AF-EzTcxn*tV%iLm zHeD1A;l>$sl!sOrqN>exZYm^6h5V}b_Bj`j8UwopF1XO+P@WPaSlhF5zaYhggI}|>M89jAFQ+O zbMcW|v)OAMO}{xJ)#moO5eU@==c+6KB5S2hV2!}MoE&Jz*$?4A=5foo7P2dZeHuvi z31Pd1EllQxf^bZF*4Px-UG8cD-;G{hFvQfJ-mqT{hC1W<2R>WnOQZ)Gd$$|#xztt^ zd$+{raGycvzvZ#4ujHMyx5eXFl~?ae=5yi__&p@xG4a)nAaR=bt^g&E7cx6$-hVHj zo}N!yynF83N6F(Rtc&L{?ca*Tvo*q=#CSZxS!wVRsVZeIdV9n#DOphBOzx&Wh5n?f zK6E^O)#A+}x@-Me{GmVfXYYUBpY0BOjJPE3&u@(W%s+%wcj`c|>FkPe4>w6qAXfM? zuz_$V9G3ejbp`Se58`_;ag})MMU49I1K=P~@;3VT>&xf%%E3DeUs@jq3g;znJtCLv zzqEfV(lQ(!r*$#HqOA@`pPJz^H2QFGZJeG3Z?g2CG0b~`sGGS!AoWVJb4@0GF5-7C zdjZhxMiEA;wkiNDTChCK~0OCW!rvLx| literal 0 HcmV?d00001 diff --git a/test/tools/llvm-objdump/X86/malformed-machos.test b/test/tools/llvm-objdump/X86/malformed-machos.test index a47e43443c5..c5778ed6f30 100644 --- a/test/tools/llvm-objdump/X86/malformed-machos.test +++ b/test/tools/llvm-objdump/X86/malformed-machos.test @@ -39,3 +39,9 @@ # RUN: | FileCheck -check-prefix=m0337 %s # m0337: subq $16, %rsp + +# RUN: llvm-objdump -macho -disassemble \ +# RUN: %p/Inputs/malformed-machos/00000031.a \ +# RUN: | FileCheck -check-prefix=0031a %s + +# 0031a: Archive -- 2.34.1