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

NewBlockFromBytes: panic: runtime error: slice bounds out of range #2193

Closed
brunoerg opened this issue May 31, 2024 · 1 comment
Closed

NewBlockFromBytes: panic: runtime error: slice bounds out of range #2193

brunoerg opened this issue May 31, 2024 · 1 comment

Comments

@brunoerg
Copy link
Contributor

brunoerg commented May 31, 2024

By applying differential fuzzing (using [email protected]), we noticed that NewBlockFromBytes may panic because of slice bounds out of range. By reproducing the issue in older releases, we noticed they do not panic, just throw an error. It seems to be caused by a recent change: d7396dc#diff-d90adfff2befe29fa72ab522be237f2565daf0abf0dc1069beff4563b13119feL1054-L1055

To reproduce the issue:

package main

import (
	"fmt"
	"github.com/btcsuite/btcd/btcutil"
)

func main() {
	var bytes = []byte{
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x20, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x01, 0x47, 0xa6, 0x00, 0x17, 0xfe, 0xff, 0xff, 0xbe,
		0x00, 0xe1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x40, 0x00, 0x00,
		0x00, 0x00, 0x3a, 0x3a, 0x3a, 0xf7, 0x7a, 0x3a, 0x3a, 0x3a, 0x3a, 0xa1,
		0xa1, 0xa1, 0x31, 0xff, 0xff, 0xff, 0x56, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1,
		0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1,
		0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1,
		0xa1, 0xa1, 0xa1, 0xa1, 0x3a, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00,
		0x40, 0x00, 0x00, 0x3a, 0x3a, 0x3a, 0x47, 0x47, 0xa6, 0x00, 0x17, 0xfe,
		0xff, 0xff, 0xfe, 0xff, 0xff, 0x7f, 0x00,
	}

	// Create a new block from the serialized bytes.
	_, err := btcutil.NewBlockFromBytes(bytes)
	if err != nil {
		fmt.Printf("NewBlockFromBytes: %v", err)
		return
	}

	fmt.Printf("Completed")
}

cc: @hax0kartik

@brunoerg brunoerg closed this as completed Jun 1, 2024
@brunoerg
Copy link
Contributor Author

brunoerg commented Jun 1, 2024

It's fixed, nevermind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant