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

anic: runtime error: slice bounds out of range [:230812] with capacity 230807 #44878

Closed
continueJ opened this issue Mar 9, 2021 · 4 comments
Closed
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@continueJ
Copy link

continueJ commented Mar 9, 2021

What version of Go are you using (go version)?

$ go version
go version go1.16 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOHOSTARCH="amd64"
GOHOSTOS="linux"

What did you do?

// include wav file header
func (p *G711WavPayloader) Payload(wav_data []byte) (rtp_payload [][]byte) {
	start := 0
	for i := 36; i < len(wav_data); i++ { 
		if string(wav_data[i:i+4]) == "data" {
			start = i + 8
			break
		}
	}
	if start == 0 {
		fmt.Errorf("data ERROR")
		return rtp_payload
	}

	for index := start; index < len(wav_data); index += PCMAPayLoadLength {
		rtp_payload = append(rtp_payload, wav_data[index:index+PCMAPayLoadLength])
	}
	return rtp_payload
}

What did you expect to see?

obtain the payload correctly

What did you see instead?

anic: runtime error: slice bounds out of range [:230812] with capacity 230807

@AlexRouSg
Copy link
Contributor

Please explain why do you think this is a bug with Go and not a bug with your code.

@ALTree ALTree added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Mar 9, 2021
@odeke-em
Copy link
Member

odeke-em commented Mar 9, 2021

@continueJ thank you for filing this issue and welcome to the Go project!

You have a bug in your program because your end index is out of range of the length as the runtime panic shows. It is expected that for a slicing range
slice[low:high] that the following condition be satisfied:
0<=low<=high<=len(slice)

Please check the slice end index with

end := index + PCMAPayLoadLength
if end > len(wav_data) {
   end = len(wav_data)
}
tp_payload = append(rtp_payload, wav_data[index:end])
}

I shall close this issue as I’ve provided a solution but please don’t hesitate to reach out and if you need to ask questions, please see these resources https://github.com/golang/go/wiki/Questions. Thank you for using Go!

@odeke-em odeke-em closed this as completed Mar 9, 2021
@davecheney
Copy link
Contributor

string(wav_data[i:i+4]) == "data" {

this line constructs a value four beyond I, without checking that it is bounded.

@continueJ
Copy link
Author

In version 14, this program can be executed correctly。This wav_data is a standard audio data for parsing。But In version 16,the returned variable rtp_payload seems that the maximum size is limited by default and leads to out of bounded

@golang golang locked and limited conversation to collaborators Apr 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

6 participants