]> Cypherpunks repositories - gostls13.git/commitdiff
debug/macho: use saferio to allocate load command slice
authorTobias Klauser <tklauser@distanz.ch>
Thu, 1 Sep 2022 08:48:58 +0000 (10:48 +0200)
committerGopher Robot <gobot@golang.org>
Fri, 2 Sep 2022 17:48:30 +0000 (17:48 +0000)
Avoid allocating large amounts of memory for corrupt input.

No test case because the problem can only happen for invalid data.
Let the fuzzer find cases like this.

Fixes #54780

Change-Id: Icdacb16bef7d29ef431da52e6d1da4e883a3e050
Reviewed-on: https://go-review.googlesource.com/c/go/+/427434
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>

src/debug/macho/file.go

index e35b4df5089ffc586e1659224280ba719f4336fc..3c9580337182792af55dde5529e6d8c7b60fe161 100644 (file)
@@ -249,8 +249,8 @@ func NewFile(r io.ReaderAt) (*File, error) {
        if f.Magic == Magic64 {
                offset = fileHeaderSize64
        }
-       dat := make([]byte, f.Cmdsz)
-       if _, err := r.ReadAt(dat, offset); err != nil {
+       dat, err := saferio.ReadDataAt(r, uint64(f.Cmdsz), offset)
+       if err != nil {
                return nil, err
        }
        c := saferio.SliceCap([]Load{}, uint64(f.Ncmd))