anacrolix / dms

A UPnP DLNA Digital Media Server that includes basic video transcoding. Tested on a Panasonic Viera television, several Android UPnP apps, and Chromecast.
BSD 3-Clause "New" or "Revised" License
646 stars 96 forks source link

fix Int63n panic #136

Closed wuxingzhong closed 1 year ago

wuxingzhong commented 1 year ago

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/dms@v1.6.0/ssdp/ssdp.go:319 +0x874 created by github.com/anacrolix/dms/ssdp.(*Server).serve /go/pkg/mod/github.com/anacrolix/dms@v1.6.0/ssdp/ssdp.go:129 +0x2c

anacrolix commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

wuxingzhong commented 1 year ago

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 commented 1 year ago

@wuxingzhong thanks for your contribution!