From 0a91f4830848ca16bf4b0569e45e23d7e8043368 Mon Sep 17 00:00:00 2001 From: Nico Rieck Date: Wed, 26 Feb 2014 19:51:44 +0000 Subject: [PATCH] Relax COFF string table check COFF object files with 0 as string table size are currently rejected. This prevents us from reading object files written by tools like cvtres that violate the PECOFF spec and write 0 instead of 4 for the size of an empty string table. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202292 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Object/COFFObjectFile.cpp | 8 ++++++-- .../Inputs/zero-string-table.obj.coff-i386 | Bin 0 -> 704 bytes .../llvm-readobj/coff-zero-string-table.test | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 test/tools/llvm-readobj/Inputs/zero-string-table.obj.coff-i386 create mode 100644 test/tools/llvm-readobj/coff-zero-string-table.test diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp index 41d21eed139..0c79506f419 100644 --- a/lib/Object/COFFObjectFile.cpp +++ b/lib/Object/COFFObjectFile.cpp @@ -409,9 +409,13 @@ error_code COFFObjectFile::initSymbolTablePtr() { getObject(StringTable, Data, StringTableAddr, StringTableSize)) return EC; + // Treat table sizes < 4 as empty because contrary to the PECOFF spec, some + // tools like cvtres write a size of 0 for an empty table instead of 4. + if (StringTableSize < 4) + StringTableSize = 4; + // Check that the string table is null terminated if has any in it. - if (StringTableSize < 4 || - (StringTableSize > 4 && StringTable[StringTableSize - 1] != 0)) + if (StringTableSize > 4 && StringTable[StringTableSize - 1] != 0) return object_error::parse_failed; return object_error::success; } diff --git a/test/tools/llvm-readobj/Inputs/zero-string-table.obj.coff-i386 b/test/tools/llvm-readobj/Inputs/zero-string-table.obj.coff-i386 new file mode 100644 index 0000000000000000000000000000000000000000..f41f224f60975e4e548c7afbb7e3ae759fdf376f GIT binary patch literal 704 zcmZ`%O-sW-5S_Jt6%<;$h^HKSutJx#LMcTdSQP~oNhFBGLz`|(B)YOmwRrO2!9#zC zKfr(CN%SUOJb3aZdQ@~KZ84?zl9!o%JF{eFXNx7^Y9?vTjQ}Je0^@a2Yc(@gcM0%? zPN%=41fy9QM0`rH(-=c@GI;&*38AY