]> Cypherpunks repositories - gostls13.git/commit
debug/elf: prevent offset overflow
authorJes Cok <xigua67damn@gmail.com>
Thu, 25 Sep 2025 04:41:12 +0000 (04:41 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 29 Sep 2025 04:38:57 +0000 (21:38 -0700)
commit5500cbf0e420a6d643835ec05f35abb170e3e443
tree5198d0d4702d169655e479a187b688850050ab05
parent34e67623a81e9e93c3d7d0f0cb257d7d722939f2
debug/elf: prevent offset overflow

When applying relocations, a malformed ELF file can provide an offset
that, when added to the relocation size, overflows. This wrapped-around
value could then incorrectly pass the bounds check, leading to a panic
when the slice is accessed with the original large offset.

This change eliminates the manual bounds and overflow checks
and writes a relocation to slice by calling putUint.

The putUint helper function centralizes the logic for validating slice
access, correctly handling both out-of-bounds and integer overflow conditions.
This simplifies the relocation code and improves robustness when parsing
malformed ELF files.

Fixes #75516

Change-Id: I00d806bf5501a9bf70200585ba4fd0475d7b2ddc
GitHub-Last-Rev: 49144311d31fecc63cb81b6c31bf9a206acb0596
GitHub-Pull-Request: golang/go#75522
Reviewed-on: https://go-review.googlesource.com/c/go/+/705075
Reviewed-by: Florian Lehner <lehner.florian86@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Commit-Queue: Ian Lance Taylor <iant@golang.org>
src/debug/elf/file.go