From: Ian Lance Taylor Date: Thu, 23 Jun 2022 23:36:08 +0000 (-0700) Subject: internal/xcoff: use saferio to read string table X-Git-Tag: go1.20rc1~1606 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0d8efa6e842169e61cbe343441092b6f7c9b886c;p=gostls13.git internal/xcoff: use saferio to read string table No test case because the problem can only happen for invalid data. Let the fuzzer find cases like this. For #47653 Fixes #52526 Change-Id: Id90a5e391a4f684f45f8d7e32608eb03b8081076 Reviewed-on: https://go-review.googlesource.com/c/go/+/413875 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: Dmitri Shuralyov TryBot-Result: Gopher Robot Reviewed-by: Tobias Klauser Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor --- diff --git a/src/internal/xcoff/file.go b/src/internal/xcoff/file.go index 553103bdff..1c5a266caf 100644 --- a/src/internal/xcoff/file.go +++ b/src/internal/xcoff/file.go @@ -9,6 +9,7 @@ import ( "debug/dwarf" "encoding/binary" "fmt" + "internal/saferio" "io" "os" "strings" @@ -213,13 +214,11 @@ func NewFile(r io.ReaderAt) (*File, error) { return nil, err } if l > 4 { - if _, err := sr.Seek(int64(offset), io.SeekStart); err != nil { - return nil, err - } - f.StringTable = make([]byte, l) - if _, err := io.ReadFull(sr, f.StringTable); err != nil { + st, err := saferio.ReadDataAt(sr, uint64(l), int64(offset)) + if err != nil { return nil, err } + f.StringTable = st } // Read section headers