Browse Source

fix error and add tests

pull/3189/head
pedro 2 years ago
parent
commit
f030913cb1
  1. 2
      internal/protocols/rtmp/amf0/unmarshal.go
  2. 37
      internal/protocols/rtmp/amf0/unmarshal_test.go

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

@ -219,7 +219,7 @@ func unmarshal(buf []byte) (interface{}, []byte, error) { @@ -219,7 +219,7 @@ func unmarshal(buf []byte) (interface{}, []byte, error) {
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])
// timeZone := uint16(buf[0])<<8 | uint16(buf[1])
buf = buf[2:] // skip timeZone
return date, buf, nil
default:

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

@ -311,3 +311,40 @@ func FuzzUnmarshal(f *testing.F) { @@ -311,3 +311,40 @@ func FuzzUnmarshal(f *testing.F) {
Unmarshal(b) //nolint:errcheck
})
}
func TestStrictArray(t *testing.T) {
data := []byte{
0x0a, 0x00, 0x00, 0x00, 0x02, 0x02, 0x00, 0x06,
0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x00, 0x40,
0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}
t.Run("strictArray", func(t *testing.T) {
dec, err := Unmarshal(data)
require.NoError(t, err)
require.Equal(t, []interface{}{nil}, dec)
})
}
func TestLongString(t *testing.T) {
data := []byte{
0x0c, 0x00, 0x00, 0x00, 0x06, 0x72, 0x61, 0x6e, 0x64,
0x6f, 0x6d,
}
t.Run("longString", func(t *testing.T) {
dec, err := Unmarshal(data)
require.NoError(t, err)
require.Equal(t, []interface{}{"random"}, dec)
})
}
func TestDate(t *testing.T) {
data := []byte{
0x0b, 0x40, 0xa3, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
}
t.Run("date", func(t *testing.T) {
dec, err := Unmarshal(data)
require.NoError(t, err)
require.Equal(t, []interface{}{float64(2500)}, dec)
})
}

Loading…
Cancel
Save