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

panic when missing credentials #1200

Closed
3 tasks done
amznpurple opened this issue Mar 31, 2021 · 3 comments · Fixed by aws/smithy-go#282
Closed
3 tasks done

panic when missing credentials #1200

amznpurple opened this issue Mar 31, 2021 · 3 comments · Fixed by aws/smithy-go#282
Assignees
Labels
bug This issue is a bug.

Comments

@amznpurple
Copy link

amznpurple commented Mar 31, 2021

Confirm by changing [ ] to [x] below to ensure that it's a bug:

Describe the bug
A clear and concise description of what the bug is.

Panic with this code:

package main
import (
	"context"
	"fmt"
	"github.com/aws/aws-sdk-go-v2/service/s3"
)
const region = "ca-central-1"
func main() {
	fmt.Printf("hello s3\n")
	options := s3.Options{
		// The region to send requests to. (Required)
		Region: region,
	}
	client := s3.New(options)
	fmt.Printf("list buckets\n")
	output, err := client.ListBuckets(context.TODO(), &s3.ListBucketsInput{}) // XXX: panics here!
	if err != nil {
return
	}
	fmt.Printf("Bucket owner: %+v\n", output.Owner) // *DisplayName or *ID
	for _, bucket := range output.Buckets {
		fmt.Printf("Bucket: %+v\n", bucket.Name)
	}
}

Version of AWS SDK for Go?
Example: v1.29.22

  • get SDK version by printing the output of aws.SDKVersion in your code after importing "github.com/aws/aws-sdk-go-v2/aws"

git master/main

Version of Go (go version)?
1.16

To Reproduce (observed behavior)
Steps to reproduce the behavior (please share code or minimal repo)

Run code.
It should not panic. It does.

Panic: runtime error: index out of range [1024] with length 1024
 
goroutine 1 [running]:
github.com/aws/smithy-go/io.(*RingBuffer).Read(0xc000486060, 0xc0000ae000, 0x200, 0x200, 0x4, 0xc000500780, 0x7f6a80365638)
	/home/purple/go/pkg/mod/github.com/aws/[email protected]/io/ringbuffer.go:63 +0xb6
bytes.(*Buffer).ReadFrom(0xc000486c90, 0x79b200, 0xc000486060, 0x7f6a80365638, 0xc000486c90, 0x1)
	/usr/lib/go-1.16/src/bytes/buffer.go:204 +0xbe
io.copyBuffer(0x79ae60, 0xc000486c90, 0x79b200, 0xc000486060, 0x0, 0x0, 0x0, 0x1, 0x1, 0x79af40)
	/usr/lib/go-1.16/src/io/io.go:409 +0x357
io.Copy(...)
	/usr/lib/go-1.16/src/io/io.go:382

Expected behavior
A clear and concise description of what you expected to happen.

Should not panic.

Additional context
Add any other context about the problem here.

When you pass in credentials, then it doesn't panic. But it's a bug that a user could ever cause a panic.

@amznpurple amznpurple added the bug This issue is a bug. label Mar 31, 2021
@skmcgrail
Copy link
Member

skmcgrail commented Apr 2, 2021

Can reproduce the panic with the following code, a very subtle bug that can only happen on certain data sizes that are a multiple of 1024. This code reproduces the same bug but just with a smaller data size.

package main

import (
	"bytes"
	"fmt"
	smithyio "github.com/aws/smithy-go/io"
	"io"
	"io/ioutil"
	"math/rand"
)

func main() {
	var data [100]byte

	_, err := rand.Read(data[:])
	if err != nil {
		panic(err)
	}

	dataReader := bytes.NewReader(data[:])

	var stack [10]byte
	ringBuffer := smithyio.NewRingBuffer(stack[:])

	reader := io.TeeReader(dataReader, ringBuffer)

	_, err = ioutil.ReadAll(reader)
	if err != nil {
		panic(err)
	}

	var buffer bytes.Buffer

	_, err = io.Copy(&buffer, ringBuffer)
	if err != nil {
		panic(err)
	}

	fmt.Printf("%x\n", buffer.String())
}

@amznpurple
Copy link
Author

/cc @purpleidea who discovered this bug.

@github-actions
Copy link

github-actions bot commented Apr 7, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

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

Successfully merging a pull request may close this issue.

3 participants