rtmp icon indicating copy to clipboard operation
rtmp copied to clipboard

panic: runtime error: index out of range

Open moneyzmey opened this issue 7 years ago • 17 comments

Hi, use your example.

start stream using OBS. got output:

2018/02/02 14:42:29 Serving RTMP on :1935
2018/02/02 14:42:38 Begin RTMP Handshake.
2018/02/02 14:42:38 Receive a C0 chunk.
2018/02/02 14:42:38 Send a S0 chunk.
2018/02/02 14:42:38 Receive a C1 chunk.
2018/02/02 14:42:38 Send a S1 chunk.
2018/02/02 14:42:38 Send a S2 chunk.
2018/02/02 14:42:38 Receive a C2 chunk.
2018/02/02 14:42:38 Set Chunk Size: 4096
2018/02/02 14:42:38 Catch AMF0 Command Message
2018/02/02 14:42:38 Receive connect command message (transactionID: 1.000000).
2018/02/02 14:42:38 Catch AMF0 Command Message
2018/02/02 14:42:38 Receive a releaseStream command (transactionID: 2.000000).
2018/02/02 14:42:38 Catch AMF0 Command Message
2018/02/02 14:42:38 Receive FCPublish command message (transactionID: 3.000000, streamName: 3818f59c-d7ad-40cf-ae16-a369589da90c).
2018/02/02 14:42:38 Catch AMF0 Command Message
2018/02/02 14:42:38 Catch createStream command message - (transactionID: 4.000000)
2018/02/02 14:42:38 Catch AMF0 Command Message
2018/02/02 14:42:38 Catch publish command message - (transactionID: 5.000000)
2018/02/02 14:42:38 Catch DataMessage(AMF0)
2018/02/02 14:42:39 Catch audio message
2018/02/02 14:42:39 Catch video message
2018/02/02 14:42:39 Catch video message
2018/02/02 14:42:39 Catch video message
2018/02/02 14:42:39 Catch video message
2018/02/02 14:42:39 Catch audio message
2018/02/02 14:42:39 Catch audio message
2018/02/02 14:42:39 Catch video message
2018/02/02 14:42:39 Catch audio message
2018/02/02 14:42:39 Catch video message
2018/02/02 14:42:39 Catch audio message
2018/02/02 14:42:39 Catch audio message
2018/02/02 14:42:39 Catch video message
2018/02/02 14:42:39 Catch audio message
2018/02/02 14:42:39 Catch video message
2018/02/02 14:42:39 Catch audio message
2018/02/02 14:42:39 Catch audio message
2018/02/02 14:42:39 Catch video message
2018/02/02 14:42:39 Catch audio message
2018/02/02 14:42:39 Catch video message
2018/02/02 14:42:39 Catch audio message
panic: runtime error: index out of range

goroutine 19 [running]:
encoding/binary.binary.bigEndian.Uint32(...)
	/usr/local/go/src/encoding/binary/binary.go:111
github.com/c-bata/rtmp.readMessageHeader(0xc4200960c0, 0xc420084c02, 0x0, 0x0, 0x0)
GolangProjects/src/github.com/c-bata/rtmp/chunk.go:246 +0x68e
github.com/c-bata/rtmp.readChunkHeader(0xc4200960c0, 0x1158e24, 0x13, 0x0)
GolangProjects/src/github.com/c-bata/rtmp/chunk.go:51 +0x67
github.com/c-bata/rtmp.(*conn).readChunk(0xc4200a6100, 0x0, 0x0)
GolangProjects/src/github.com/c-bata/rtmp/conn.go:196 +0x47
github.com/c-bata/rtmp.(*conn).serve(0xc4200a6100, 0xc4200c9000, 0x1000)
GolangProjects/src/github.com/c-bata/rtmp/conn.go:81 +0x102
created by github.com/c-bata/rtmp.(*Server).Serve
GolangProjects/src/github.com/c-bata/rtmp/server.go:56 +0x4dd

moneyzmey avatar Feb 02 '18 07:02 moneyzmey

Hmm... It's difficult to find the cause of this problem from the log you pasted. I need to check what bytes are sent from rtmp client.

Could you run the proxy and paste the output?

$ go run _example/server/main.go -addr :1936

After that

$ go run _example/proxy/main.go -laddr :1935 -raddr :1936
...

c-bata avatar Feb 02 '18 13:02 c-bata

first example:

$ go run _example/server/main.go -addr :1936

output:

2018/02/06 14:55:16 Serving RTMP on :1936 (rev-)
2018/02/06 14:55:30 Begin RTMP Handshake.
2018/02/06 14:55:30 Receive a C0 chunk.
2018/02/06 14:55:30 Send a S0 chunk.
2018/02/06 14:55:30 Receive a C1 chunk.
2018/02/06 14:55:30 Send a S1 chunk.
2018/02/06 14:55:30 Send a S2 chunk.
2018/02/06 14:55:30 Receive a C2 chunk.
2018/02/06 14:55:30 Set Chunk Size: 4096
2018/02/06 14:55:30 Catch AMF0 Command Message
2018/02/06 14:55:30 Receive connect command message (transactionID: 1.000000).
2018/02/06 14:55:30 Catch AMF0 Command Message
2018/02/06 14:55:30 Receive a releaseStream command (transactionID: 2.000000).
2018/02/06 14:55:30 Catch AMF0 Command Message
2018/02/06 14:55:30 Receive FCPublish command message (transactionID: 3.000000, streamName: 3818f59c-d7ad-40cf-ae16-a369589da90c).
2018/02/06 14:55:30 Catch AMF0 Command Message
2018/02/06 14:55:30 Catch createStream command message - (transactionID: 4.000000)
2018/02/06 14:55:30 Catch AMF0 Command Message
2018/02/06 14:55:30 Catch publish command message - (transactionID: 5.000000)
2018/02/06 14:55:30 Catch DataMessage(AMF0)
2018/02/06 14:55:31 Catch audio message
2018/02/06 14:55:31 Catch video message
2018/02/06 14:55:31 Catch video message
2018/02/06 14:55:31 Catch unknown message type id: 135
2018/02/06 14:55:31 &rtmp.BasicHeader{FMT:0x0, ChunkStreamID:0x3a}
2018/02/06 14:55:31 &rtmp.MessageHeader{Timestamp:0xb23a6d, TimestampDelta:0x0, MessageLength:0x12c091, MessageTypeID:0x87, MessageStreamID:0x6d0d07e9}
2018/02/06 14:55:33 Catch unknown message type id: 0
2018/02/06 14:55:33 &rtmp.BasicHeader{FMT:0x3, ChunkStreamID:0x3f}
2018/02/06 14:55:33 &rtmp.MessageHeader{Timestamp:0x0, TimestampDelta:0x0, MessageLength:0x0, MessageTypeID:0x0, MessageStreamID:0x0}
2018/02/06 14:55:33 Catch unknown message type id: 0
2018/02/06 14:55:33 &rtmp.BasicHeader{FMT:0x3, ChunkStreamID:0x3f}
2018/02/06 14:55:33 &rtmp.MessageHeader{Timestamp:0x0, TimestampDelta:0x0, MessageLength:0x0, MessageTypeID:0x0, MessageStreamID:0x0}
2018/02/06 14:55:33 Catch unknown message type id: 0
2018/02/06 14:55:33 &rtmp.BasicHeader{FMT:0x3, ChunkStreamID:0x3f}
<CUT SOME PART LOG TOO BIG>
2018/02/06 14:55:33 &rtmp.MessageHeader{Timestamp:0x0, TimestampDelta:0x0, MessageLength:0x0, MessageTypeID:0x0, MessageStreamID:0x0}
2018/02/06 14:55:33 Catch unknown message type id: 0
2018/02/06 14:55:33 &rtmp.BasicHeader{FMT:0x3, ChunkStreamID:0x3f}
2018/02/06 14:55:33 &rtmp.MessageHeader{Timestamp:0x0, TimestampDelta:0x0, MessageLength:0x0, MessageTypeID:0x0, MessageStreamID:0x0}
2018/02/06 14:55:33 Catch unknown message type id: 0
2018/02/06 14:55:33 &rtmp.BasicHeader{FMT:0x3, ChunkStreamID:0x3f}
2018/02/06 14:55:33 &rtmp.MessageHeader{Timestamp:0x0, TimestampDelta:0x0, MessageLength:0x0, MessageTypeID:0x0, MessageStreamID:0x0}
2018/02/06 14:55:33 Catch unknown message type id: 0
2018/02/06 14:55:33 &rtmp.BasicHeader{FMT:0x3, ChunkStreamID:0x3f}
2018/02/06 14:55:33 &rtmp.MessageHeader{Timestamp:0x0, TimestampDelta:0x0, MessageLength:0x0, MessageTypeID:0x0, MessageStreamID:0x0}
panic: runtime error: index out of range

goroutine 19 [running]:
encoding/binary.binary.bigEndian.Uint32(...)
	/usr/local/go/src/encoding/binary/binary.go:111
github.com/c-bata/rtmp.readMessageHeader(0xc4200900c0, 0xc42018ef02, 0x0, 0x0, 0x0)
	/GolangProjects/src/github.com/c-bata/rtmp/chunk.go:246 +0x68e
github.com/c-bata/rtmp.readChunkHeader(0xc4200900c0, 0xc4200900c0, 0x122f7a8, 0x0)
	/GolangProjects/src/github.com/c-bata/rtmp/chunk.go:51 +0x67
github.com/c-bata/rtmp.(*conn).readChunk(0xc4200a0100, 0x0, 0x0)
	/GolangProjects/src/github.com/c-bata/rtmp/conn.go:196 +0x47
github.com/c-bata/rtmp.(*conn).serve(0xc4200a0100, 0xc4200c3000, 0x1000)
	/GolangProjects/src/github.com/c-bata/rtmp/conn.go:81 +0x102
created by github.com/c-bata/rtmp.(*Server).Serve
	/GolangProjects/src/github.com/c-bata/rtmp/server.go:56 +0x4dd

moneyzmey avatar Feb 06 '18 08:02 moneyzmey

Thank you for trying this. But sorry, could you paste the output of proxy? Maybe it's really long, so if you can't paste all output in this comment area, please paste the last two blocks of byte streams.

c-bata avatar Feb 06 '18 08:02 c-bata

in process right now ;)

moneyzmey avatar Feb 06 '18 08:02 moneyzmey

About proxy, i got connection refused.

output:

2018/02/06 15:09:01 Listening: :1935
2018/02/06 15:09:01 Proxying: :1936
2018/02/06 15:09:04 tcpproxy: for incoming conn 127.0.0.1:53189, error dialing ":1936": dial tcp :1936: getsockopt: connection refused

moneyzmey avatar Feb 06 '18 08:02 moneyzmey

Hmm....? Did you run rtmp server at :1936 port?

c-bata avatar Feb 06 '18 08:02 c-bata

Yes, it my mistake, forgot to do it last two blocks:

>>>>>>>>>>>>>>>>>>>> Source -> Destination >>>>>>>>>>>>>>>>>>>
00000000  44 00 00 07 00 01 d2 08  af 01 21 00 03 40 68 1b  |D.........!..@h.|
00000010  ff c0 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000060  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000070  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000080  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000090  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000100  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000110  00 00 00 00 00 00 00 00  00 00 00 00 00 00 37 d5  |..............7.|
00000120  80 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000130  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000140  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000150  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000160  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000170  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000180  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000190  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001d0  00 00 00 00 00 00 00 00  00 70                    |.........p|

>>>>>>>>>>>>>>>>>>>> Source -> Destination >>>>>>>>>>>>>>>>>>>
00000000  44 00 00 17 00 01 d3 08  af 01 21 00 03 40 68 1b  |D.........!..@h.|
00000010  ff c0 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000060  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000070  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000080  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000090  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000100  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000110  00 00 00 00 00 00 00 00  00 00 00 00 00 00 37 d6  |..............7.|
00000120  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000130  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000140  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000150  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000160  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000170  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000180  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000190  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001d0  00 00 00 00 00 00 00 00  00 00 70                 |..........p|

moneyzmey avatar Feb 06 '18 08:02 moneyzmey

Thank you. I'll check the bytes. It may take a while, but please wait.

c-bata avatar Feb 06 '18 08:02 c-bata

Sure, thank you so much!

moneyzmey avatar Feb 06 '18 08:02 moneyzmey

add full log file testlogfile.zip

moneyzmey avatar Feb 06 '18 08:02 moneyzmey

Thank you. great job!

c-bata avatar Feb 06 '18 08:02 c-bata

May I ask your email address ?

moneyzmey avatar Feb 06 '18 10:02 moneyzmey

Sorry, no soliciting is allowed.

c-bata avatar Feb 06 '18 15:02 c-bata

ok, understood.

moneyzmey avatar Feb 06 '18 15:02 moneyzmey

Do you have any idea ?

moneyzmey avatar Feb 07 '18 04:02 moneyzmey

Same problem here...

gizmocuz avatar May 14 '18 14:05 gizmocuz

@saturday06 tells me the cause of this problem might be below:

  1. When FMT field in chunk basic header is 2 or 3, we need to re-use chunk data from the previous received one.
  2. Sometimes the length of chunk data doesn't match that client sends.

I don't know how can I fix the second one. But anyway, I'll investigate this problem again. Thanks

c-bata avatar Jun 25 '18 05:06 c-bata