]> Cypherpunks repositories - gostls13.git/commitdiff
internal/xcoff: use saferio to read string table
authorIan Lance Taylor <iant@golang.org>
Thu, 23 Jun 2022 23:36:08 +0000 (16:36 -0700)
committerGopher Robot <gobot@golang.org>
Wed, 17 Aug 2022 03:11:57 +0000 (03:11 +0000)
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 <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>

src/internal/xcoff/file.go

index 553103bdff818ca42ad1e9919088371855b1ca6b..1c5a266caffb21f3ab5512400afbcba3e6d82cf9 100644 (file)
@@ -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