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

fix Int63n panic #136

Merged
merged 2 commits into from
Nov 11, 2023
Merged

fix Int63n panic #136

merged 2 commits into from
Nov 11, 2023

Conversation

wuxingzhong
Copy link
Contributor

2023/11/09 11:05:05 INFO : /static/ContentDirectory.xml: 192.168.131.174:52716 GET 200
panic: invalid argument to Int63n

goroutine 1933 [running]:
math/rand.(*Rand).Int63n(0x140000008c0?, 0x14000046e70?)
/opt/homebrew/Cellar/go/1.20.6/libexec/src/math/rand/rand.go:121 +0xe8
math/rand.Int63n(...)
/opt/homebrew/Cellar/go/1.20.6/libexec/src/math/rand/rand.go:348
github.com/anacrolix/dms/ssdp.(*Server).handle(0x140000008c0, {0x14000706c00, 0x65, 0x5dc}, 0x1400057cfc0?)
/go/pkg/mod/github.com/anacrolix/[email protected]/ssdp/ssdp.go:319 +0x874
created by github.com/anacrolix/dms/ssdp.(*Server).serve
/go/pkg/mod/github.com/anacrolix/[email protected]/ssdp/ssdp.go:129 +0x2c

@anacrolix
Copy link
Owner

There's a check for 0 mx above, and it's a uint. For this to happen, surely you have something returning a huge mx that overflows when multiplied by time.Second. Have I missed something?

@wuxingzhong
Copy link
Contributor Author

There's a check for 0 mx above, and it's a uint. For this to happen, surely you have something returning a huge mx that overflows when multiplied by time.Second. Have I missed something?

yes, a huge mx that overflows when change uint to int64 On 64-bit systems.

func TestUint(t *testing.T) {
	mx := uint(9223372036854775808)
	fmt.Println("mx:", mx)
	fmt.Println("mx2:", int64(mx))
}

output:

mx: 9223372036854775808
mx2: -9223372036854775808

Maybe we should limit the maximum value of mx?

@anacrolix
Copy link
Owner

Do you have a misbehaving system on your network to cause this?

@wuxingzhong
Copy link
Contributor Author

Do you have a misbehaving system on your network to cause this?

I'm using vlc to play the files on the dlna server, which may panic once in a while

@anacrolix anacrolix merged commit f4b323a into anacrolix:master Nov 11, 2023
1 check failed
@anacrolix
Copy link
Owner

@wuxingzhong thanks for your contribution!

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

Successfully merging this pull request may close these issues.

2 participants