From 691c5c156878799ec15683f10e24d9a924ea7996 Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Fri, 17 Jun 2016 14:05:35 +1000 Subject: [PATCH] debug/pe: handle files with no string table pecoff.doc (https://goo.gl/ayvckk) in section 5.6 says: Immediately following the COFF symbol table is the COFF string table. The position of this table is found by taking the symbol table address in the COFF header, and adding the number of symbols multiplied by the size of a symbol. So it is unclear what to do when symbol table address is 0. Lets assume executable does not have any string table. Added new test with executable with no symbol table. The gcc -s testdata\hello.c -o testdata\gcc-386-mingw-no-symbols-exec. command was used to generate the executable. Fixes #16084 Change-Id: Ie74137ac64b15daadd28e1f0315f3b62d1bf2059 Reviewed-on: https://go-review.googlesource.com/24200 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- src/debug/pe/file_test.go | 35 ++++++++++++++++++ src/debug/pe/string.go | 3 ++ .../pe/testdata/gcc-386-mingw-no-symbols-exec | Bin 0 -> 8704 bytes 3 files changed, 38 insertions(+) create mode 100644 src/debug/pe/testdata/gcc-386-mingw-no-symbols-exec diff --git a/src/debug/pe/file_test.go b/src/debug/pe/file_test.go index 12059b5eff..964caf56ec 100644 --- a/src/debug/pe/file_test.go +++ b/src/debug/pe/file_test.go @@ -104,6 +104,41 @@ var fileTests = []fileTest{ {".debug_loc", 0x38, 0xf000, 0x200, 0x3a00, 0x0, 0x0, 0x0, 0x0, 0x42100000}, }, }, + { + file: "testdata/gcc-386-mingw-no-symbols-exec", + hdr: FileHeader{0x14c, 0x8, 0x69676572, 0x0, 0x0, 0xe0, 0x30f}, + opthdr: &OptionalHeader32{0x10b, 0x2, 0x18, 0xe00, 0x1e00, 0x200, 0x1280, 0x1000, 0x2000, 0x400000, 0x1000, 0x200, 0x4, 0x0, 0x1, 0x0, 0x4, 0x0, 0x0, 0x9000, 0x400, 0x5306, 0x3, 0x0, 0x200000, 0x1000, 0x100000, 0x1000, 0x0, 0x10, + [16]DataDirectory{ + {0x0, 0x0}, + {0x6000, 0x378}, + {0x0, 0x0}, + {0x0, 0x0}, + {0x0, 0x0}, + {0x0, 0x0}, + {0x0, 0x0}, + {0x0, 0x0}, + {0x0, 0x0}, + {0x8004, 0x18}, + {0x0, 0x0}, + {0x0, 0x0}, + {0x60b8, 0x7c}, + {0x0, 0x0}, + {0x0, 0x0}, + {0x0, 0x0}, + }, + }, + sections: []*SectionHeader{ + {".text", 0xc64, 0x1000, 0xe00, 0x400, 0x0, 0x0, 0x0, 0x0, 0x60500060}, + {".data", 0x10, 0x2000, 0x200, 0x1200, 0x0, 0x0, 0x0, 0x0, 0xc0300040}, + {".rdata", 0x134, 0x3000, 0x200, 0x1400, 0x0, 0x0, 0x0, 0x0, 0x40300040}, + {".eh_fram", 0x3a0, 0x4000, 0x400, 0x1600, 0x0, 0x0, 0x0, 0x0, 0x40300040}, + {".bss", 0x60, 0x5000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0300080}, + {".idata", 0x378, 0x6000, 0x400, 0x1a00, 0x0, 0x0, 0x0, 0x0, 0xc0300040}, + {".CRT", 0x18, 0x7000, 0x200, 0x1e00, 0x0, 0x0, 0x0, 0x0, 0xc0300040}, + {".tls", 0x20, 0x8000, 0x200, 0x2000, 0x0, 0x0, 0x0, 0x0, 0xc0300040}, + }, + hasNoDwarfInfo: true, + }, { file: "testdata/gcc-amd64-mingw-obj", hdr: FileHeader{0x8664, 0x6, 0x0, 0x198, 0x12, 0x0, 0x4}, diff --git a/src/debug/pe/string.go b/src/debug/pe/string.go index f5cd130b53..69837f6d01 100644 --- a/src/debug/pe/string.go +++ b/src/debug/pe/string.go @@ -24,6 +24,9 @@ type _StringTable []byte func readStringTable(fh *FileHeader, r io.ReadSeeker) (_StringTable, error) { // COFF string table is located right after COFF symbol table. + if fh.PointerToSymbolTable <= 0 { + return nil, nil + } offset := fh.PointerToSymbolTable + COFFSymbolSize*fh.NumberOfSymbols _, err := r.Seek(int64(offset), io.SeekStart) if err != nil { diff --git a/src/debug/pe/testdata/gcc-386-mingw-no-symbols-exec b/src/debug/pe/testdata/gcc-386-mingw-no-symbols-exec new file mode 100644 index 0000000000000000000000000000000000000000..329dca60b91ad5e23a0522dfd7dd9b33a8b30349 GIT binary patch literal 8704 zcmeHM4{#LK8GpA~;7r2aDWTl72dte#V+)z2qD4w(4ldzukTVGm6*RfzHgI~mOYimq zSZaft1FvVCQ&Bq(%owGkwH?Q?3}Mpl@1mD3?XlFn zbZPyjKvZsvgf~Wft#Y$36bh?ylOjiAAvq9|tJc)Xtzo}XHg#&D%QWq+W~|0yWf5g# zAm?p}*$Rp*f`dt*%mN6EbzA~$2gm@5j^?0K+!g>~K2o@1F}aTMyto3%k^;x$h>NpE z#veDFy{Ca-JV9qwtWgcM=Dd5Eh-lNVq7RL%5^*m%rP37x3SFcQ+=58&}B@J zGoxDM4L2+AEsJCY=TkAt0VG$FCxj{F+-1t9h8FD3LzJ@{Kt8_$$QxX)DHEO!N)_$;p7cL2`M^ z3)9b0fjVtuLHGP}H;ebG&LdSWE7<}TsqRNa7cGr`ZKN1;`^9diKT^b)HX`a*Vxx6w z5@TIeuDOXSm%W?GZm!9^z@kee1RhxczZi0*z*hZ(LdLos;KJpSsx1x3cXDJ)X0 zLxPF4ekVi{PM3ZHxJ$i^p&q5lDpz?Dij{XW*1Nf~vI{7(`dPZOs4|og@}o-WYoVr% zS!|u}V-@eU#UBE$=+*j4*B=sDS39fR1!Z+r<^6FYqzcUVAP?2n`L~Y@14Vc0e?qZQ zRp;=VpmgnrbJlh6azfgO6A_YYWBOR5o9Vaw0}|MX34EyM_^T%JyX|NnV<<6d%6E%= zoyv{1iMO>8M|ZKz+if9y;UUQMKO#7z}=s=T=QORWP%cG zmr~Iv47$O1e28t^WX3WNq4CZAsOZhFPAau~_qxQPtLTyL-Lre$o{IjT(%jbh6WFP% z=(Rmeeft0wJU-jQqlYc(6m6;#`B+8|cjV^6-w)C8kXwqhWaE-nz7%p?`}RMAE9RE+ z==0-}?vA(RSQ%|ih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