Browse Source

Merge bd6214433b into 50322fc14e

pull/3189/merge
Pedro Sánchez 2 years ago committed by GitHub
parent
commit
64c99b2a67
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 41
      internal/protocols/rtmp/amf0/unmarshal.go
  2. 31
      internal/protocols/rtmp/amf0/unmarshal_test.go

41
internal/protocols/rtmp/amf0/unmarshal.go

@ -180,9 +180,48 @@ func unmarshal(buf []byte) (interface{}, []byte, error) { @@ -180,9 +180,48 @@ func unmarshal(buf []byte) (interface{}, []byte, error) {
return out, buf[1:], nil
case markerNull:
case markerNull, markerUnsupported, markerUndefined:
return nil, buf, nil
case markerStrictArray:
if len(buf) < 4 {
return nil, nil, errBufferTooShort
}
keyLen := uint32(buf[0])<<24 | uint32(buf[1])<<16 | uint32(buf[2])<<8 | uint32(buf[3])
buf = buf[4:]
for i := 0; i < int(keyLen); i++ {
var buffData []byte
var err error
_, buffData, err = unmarshal(buf)
if err != nil {
return nil, nil, err
}
buf = buffData
}
return nil, buf, nil
case markerLongString, markerXMLDocument:
if len(buf) < 4 {
return nil, nil, errBufferTooShort
}
keyLen := uint32(buf[0])<<24 | uint32(buf[1])<<16 | uint32(buf[2])<<8 | uint32(buf[3])
buf = buf[4:]
if len(buf) < int(keyLen) {
return nil, nil, errBufferTooShort
}
return string(buf[:keyLen]), buf[keyLen:], nil
case markerDate:
if len(buf) < 10 {
return nil, nil, errBufferTooShort
}
date := math.Float64frombits(uint64(buf[0])<<56 | uint64(buf[1])<<48 | uint64(buf[2])<<40 | uint64(buf[3])<<32 |
uint64(buf[4])<<24 | uint64(buf[5])<<16 | uint64(buf[6])<<8 | uint64(buf[7]))
buf = buf[8:]
// timeZone := uint16(buf[0])<<8 | uint16(buf[1])
buf = buf[2:] // skip timeZone
return date, buf, nil
default:
return nil, nil, fmt.Errorf("unsupported marker 0x%.2x", marker)
}

31
internal/protocols/rtmp/amf0/unmarshal_test.go

@ -290,6 +290,37 @@ var cases = []struct { @@ -290,6 +290,37 @@ var cases = []struct {
float64(0),
},
},
{
"strictArray",
[]byte{
0x0a, 0x00, 0x00, 0x00, 0x02, 0x02, 0x00, 0x06,
0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x00, 0x40,
0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
[]interface{}{
nil,
},
},
{
"longString",
[]byte{
0x0c, 0x00, 0x00, 0x00, 0x06, 0x72, 0x61, 0x6e, 0x64,
0x6f, 0x6d,
},
[]interface{}{
"random",
},
},
{
"date",
[]byte{
0x0b, 0x40, 0xa3, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
},
[]interface{}{
float64(2500),
},
},
}
func TestUnmarshal(t *testing.T) {

Loading…
Cancel
Save