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

Decoding a media playlist which has #EXT-X-KEY without any segments causes panic #25

Closed
iivarih opened this issue Aug 31, 2015 · 1 comment
Labels

Comments

@iivarih
Copy link
Contributor

iivarih commented Aug 31, 2015

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x3efcb]

goroutine 1 [running]:
github.com/grafov/m3u8.decodeLineOfMediaPlaylist(0x20821e7e0, 0x20827a000, 0x208256000, 0x0, 0x0, 0x1, 0x0, 0x0)
    /Users/iivari/go/src/github.com/grafov/m3u8/reader.go:478 +0x2b0b

how to reproduce:

main.go:

package main

import (
    "github.com/grafov/m3u8"
    "os"
    "bufio"
)

func main() {
    m3u8.DecodeFrom(bufio.NewReader(os.Stdin), true)
}

test.m3u8:

#EXTM3U
#EXT-X-VERSION:2
#EXT-X-TARGETDURATION:9
#EXT-X-KEY:METHOD=AES-128,URI="http://localhost:20001/key?ecm=AAAAAQAAOpgCAAHFYAaVFH6QrFv2wYU1lEaO2L3fGQB1%2FR3oaD9auWtXNAmcVLxgRTvRlHpqHgXX1YY00%2FpdUiOlgONVbViqou2%2FItyDOWc%3D",IV=0X00000000000000000000000000000000

$cat test.m3u8 | go run main.go

After debbugging this for a while I came up with the following fix:

diff --git a/reader.go b/reader.go
index 770d97f..4b58054 100644
--- a/reader.go
+++ b/reader.go
@@ -163,6 +163,11 @@ func decode(buf *bytes.Buffer, strict bool) (Playlist, ListType, error) {
                        break
                }

+               // possible fix...
+               if len(line) < 1 {
+                       break
+               }
+
                err = decodeLineOfMasterPlaylist(master, state, line, strict)
                if strict && err != nil {
                        return master, state.listType, err
@iivarih
Copy link
Contributor Author

iivarih commented Aug 31, 2015

Blank lines should be ignored so instead of break there should be continue (http://tools.ietf.org/html/draft-pantos-http-live-streaming-12#section-3.1). That would solve this problem and also not decode any blank lines in the buffer.

@grafov grafov added the bug label Aug 31, 2015
@grafov grafov closed this as completed in 6acbc3b Sep 1, 2015
grafov added a commit that referenced this issue Nov 22, 2016
Fixes decoding empty lines, partially closes #25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants