From: Alex Brainman Date: Fri, 17 Jun 2016 04:05:35 +0000 (+1000) Subject: debug/pe: handle files with no string table X-Git-Tag: go1.7rc1~85 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=691c5c156878799ec15683f10e24d9a924ea7996;p=gostls13.git 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 --- 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 0000000000..329dca60b9 Binary files /dev/null and b/src/debug/pe/testdata/gcc-386-mingw-no-symbols-exec differ