diff --git a/rtmp/chunk.go b/rtmp/chunk.go index 430aaa3..52bf060 100644 --- a/rtmp/chunk.go +++ b/rtmp/chunk.go @@ -4,6 +4,7 @@ import ( "net" "time" "encoding/binary" + "errors" ) // data intake object, only needed since most of the work is @@ -189,7 +190,9 @@ func read_message_header_1(conn net.Conn, chnk_stream_ptr *ChunkStream, msg_ptr func read_message_header_2(conn net.Conn, chnk_stream_ptr *ChunkStream, msg_ptr *Message, chunk_bufs_ptr *ChunkBuffers) (error) { var extended_time bool var err error - + if chnk_stream_ptr == nil { + panic(err) + } chnk_stream_ptr.timedelta, extended_time, err = read_time(conn, chunk_bufs_ptr) if err != nil { return err @@ -269,6 +272,9 @@ func ReadChunk(conn net.Conn, open_chnkstrms map[uint32]*ChunkStream, open_msgs // format 1, chunkstream with this csid MUST have been opened before, but message is just starting since // message metadata is being declared chnkstream_ptr = open_chnkstrms[csid] + if chnkstream_ptr == nil { + return nil, errors.New("Chunkstream was not opened, bad obs") + } msg_ptr = new(Message) if err := read_message_header_1(conn, chnkstream_ptr, msg_ptr, chunk_bufs_ptr); err != nil { @@ -281,6 +287,9 @@ func ReadChunk(conn net.Conn, open_chnkstrms map[uint32]*ChunkStream, open_msgs case 2: // format 2, same as 1 chnkstream_ptr = open_chnkstrms[csid] + if chnkstream_ptr == nil { + return nil, errors.New("Chunkstream was not opened, bad obs") + } msg_ptr = new(Message) if err := read_message_header_2(conn, chnkstream_ptr, msg_ptr, chunk_bufs_ptr); err != nil { @@ -294,6 +303,9 @@ func ReadChunk(conn net.Conn, open_chnkstrms map[uint32]*ChunkStream, open_msgs // format 3 has no header, only happens when either a previous message over the csid was too large for the chunksize // or a new message with the same exact metadata including timedelta is being sent. chnkstream_ptr = open_chnkstrms[csid] + if chnkstream_ptr == nil { + return nil, errors.New("Chunkstream was not opened, bad obs") + } msg_prev, ok := open_msgs[chnkstream_ptr.last_msg_strm_id] if !ok { msg_ptr = new(Message)