Commit 4a6dfda4 authored by Robert Griesemer's avatar Robert Griesemer

debug/macho: don't crash when reading non-Mach-O files

R=rsc
CC=golang-dev
https://golang.org/cl/838046
parent d4a16197
......@@ -167,7 +167,7 @@ func NewFile(r io.ReaderAt) (*File, os.Error) {
// Read and decode Mach magic to determine byte order, size.
// Magic32 and Magic64 differ only in the bottom bit.
var ident [4]uint8
var ident [4]byte
if _, err := r.ReadAt(&ident, 0); err != nil {
return nil, err
}
......@@ -180,6 +180,8 @@ func NewFile(r io.ReaderAt) (*File, os.Error) {
case le &^ 1:
f.ByteOrder = binary.LittleEndian
f.Magic = le
default:
return nil, &FormatError{0, "invalid magic number", nil}
}
// Read entire file header.
......
......@@ -157,3 +157,11 @@ func TestOpen(t *testing.T) {
}
}
func TestOpenFailure(t *testing.T) {
filename := "file.go" // not a Mach-O file
_, err := Open(filename) // don't crash
if err == nil {
t.Errorf("open %s: succeeded unexpectedly", filename)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment