Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/proc: failed to call method on struct type: write out of bounds #3364

Closed
ZekeLu opened this issue May 11, 2023 · 0 comments · Fixed by #3365
Closed

pkg/proc: failed to call method on struct type: write out of bounds #3364

ZekeLu opened this issue May 11, 2023 · 0 comments · Fixed by #3365

Comments

@ZekeLu
Copy link
Contributor

ZekeLu commented May 11, 2023

  1. What version of Delve are you using (dlv version)?
Delve Debugger
Version: 1.20.2
Build: $Id: e0c278ad8e0126a312b553b8e171e81bcbd37f60 $
  1. What version of Go are you using? (go version)?
go version go1.20.4 linux/amd64
  1. What operating system and processor architecture are you using?
linux/amd64
  1. What did you do?

Take the following program:

package main

import (
	"fmt"
	"runtime"
)

type T struct {
	a int
	b uint32
}

func (t T) String() string {
	return fmt.Sprintf("%d %d", t.a, t.b)
}

func main() {
	t := T{a: 1, b: 2}
	runtime.Breakpoint()
	fmt.Println(t.String())
}

and ran:

dlv debug
(dlv) c
(dlv) call t.String()
  1. What did you expect to see?
(dlv) call t.String()
> main.main() ./main.go:20 (PC: 0x49ecbf)
Values returned:
	~r0: "1 2"
  1. What did you see instead?
(dlv) call t.String()
> main.main() ./main.go:20 (PC: 0x49ecbf)
Command failed: write out of bounds

PS:

This bug is based on a real use case to print the value of github.com/shopspring/decimal.Decimal. This is the definition of decimal.Decimal:

type Decimal struct {
	value *big.Int
	exp int32
}

See also this question https://stackoverflow.com/questions/76222724/is-it-possible-to-preview-github-com-shopspring-decimal-values-in-vscode-during.

ZekeLu added a commit to ZekeLu/delve that referenced this issue May 11, 2023
On 64 bit system, the byte size of th following struct is 16:
    type myStruct struct {
       a int
       b uint32
    }
But extractVarInfoFromEntry only allocates a mem of 12 bytes for it.
When calling method of this struct with the "call" command, it will
result in this error:
    write out of bounds

This patch extends the mem by adding padding bytes to the end of the
mem.

Fixes go-delve#3364.
ZekeLu added a commit to ZekeLu/delve that referenced this issue May 11, 2023
On 64 bit system, the byte size of the following struct is 16:
    type myStruct struct {
       a int
       b uint32
    }
But extractVarInfoFromEntry only allocates a mem of 12 bytes for it.
When calling method of this struct with the "call" command, it will
result in this error:
    write out of bounds

This patch extends the mem by adding padding bytes to the end of the
mem.

Fixes go-delve#3364.
derekparker pushed a commit that referenced this issue May 15, 2023
* pkg/proc: pad variable mem in extractVarInfoFromEntry

On 64 bit system, the byte size of the following struct is 16:
    type myStruct struct {
       a int
       b uint32
    }
But extractVarInfoFromEntry only allocates a mem of 12 bytes for it.
When calling method of this struct with the "call" command, it will
result in this error:
    write out of bounds

This patch extends the mem by adding padding bytes to the end of the
mem.

Fixes #3364.

* move the padding logic into newCompositeMemory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants