Skip to content

Commit f4e7a6b

Browse files
committed
cmd/internal/goobj: fix buglet in object file reader
The code in the new (introduced in 1.15) Go object file reader was casting a pointer-mmaped-memory into a large array prior to performing a read of the relocations section: return (*[1<<20]Reloc)(unsafe.Pointer(&r.b[off]))[:n:n] For very large object files, this artificial array isn't large enough (that is, there are more than 1048576 relocs to read), so update the code to use a larger artifical array size. Fixes #41621. Change-Id: Ic047c8aef4f8a3839f2e7e3594bce652ebd6bd5b Reviewed-on: https://go-review.googlesource.com/c/go/+/278492 Run-TryBot: Than McIntosh <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Cherry Zhang <[email protected]> Reviewed-by: Jeremy Faller <[email protected]> Trust: Than McIntosh <[email protected]>
1 parent 75e16f5 commit f4e7a6b

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/cmd/internal/goobj/objfile.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,11 @@ func (r *RefFlags) SetFlag2(x uint8) { r[9] = x }
483483

484484
func (r *RefFlags) Write(w *Writer) { w.Bytes(r[:]) }
485485

486+
// Used to construct an artifically large array type when reading an
487+
// item from the object file relocs section or aux sym section (needs
488+
// to work on 32-bit as well as 64-bit). See issue 41621.
489+
const huge = (1<<31 - 1) / RelocSize
490+
486491
// Referenced symbol name.
487492
//
488493
// Serialized format:
@@ -792,7 +797,7 @@ func (r *Reader) Reloc(i uint32, j int) *Reloc {
792797
func (r *Reader) Relocs(i uint32) []Reloc {
793798
off := r.RelocOff(i, 0)
794799
n := r.NReloc(i)
795-
return (*[1 << 20]Reloc)(unsafe.Pointer(&r.b[off]))[:n:n]
800+
return (*[huge]Reloc)(unsafe.Pointer(&r.b[off]))[:n:n]
796801
}
797802

798803
// NAux returns the number of aux symbols of the i-th symbol.
@@ -818,7 +823,7 @@ func (r *Reader) Aux(i uint32, j int) *Aux {
818823
func (r *Reader) Auxs(i uint32) []Aux {
819824
off := r.AuxOff(i, 0)
820825
n := r.NAux(i)
821-
return (*[1 << 20]Aux)(unsafe.Pointer(&r.b[off]))[:n:n]
826+
return (*[huge]Aux)(unsafe.Pointer(&r.b[off]))[:n:n]
822827
}
823828

824829
// DataOff returns the offset of the i-th symbol's data.

0 commit comments

Comments
 (0)