improve MPEG4AudioLATM (#251)

This commit is contained in:
Alessandro Ros
2023-04-15 13:04:16 +02:00
committed by GitHub
parent 03013f1a87
commit f5aedf9b7f
6 changed files with 65 additions and 44 deletions

View File

@@ -711,6 +711,59 @@ func TestUnmarshalMPEG4AudioGenericErrors(t *testing.T) {
require.Error(t, err) require.Error(t, err)
} }
func TestUnmarshalMPEG4AudioLATMErrors(t *testing.T) {
_, err := Unmarshal("audio", 96, "MP4A-LATM/48000/2", map[string]string{
"profile-level-id": "aaa",
})
require.Error(t, err)
_, err = Unmarshal("audio", 96, "MP4A-LATM/48000/2", map[string]string{
"bitrate": "aaa",
})
require.Error(t, err)
_, err = Unmarshal("audio", 96, "MP4A-LATM/48000/2", map[string]string{
"object": "aaa",
})
require.Error(t, err)
_, err = Unmarshal("audio", 96, "MP4A-LATM/48000/2", map[string]string{
"object": "120",
})
require.Error(t, err)
_, err = Unmarshal("audio", 96, "MP4A-LATM/48000/2", map[string]string{
"cpresent": "aaa",
})
require.Error(t, err)
_, err = Unmarshal("audio", 96, "MP4A-LATM/48000/2", map[string]string{
"config": "aaa",
})
require.Error(t, err)
_, err = Unmarshal("audio", 96, "MP4A-LATM/48000/2", map[string]string{
"sbr-enabled": "aaa",
})
require.Error(t, err)
_, err = Unmarshal("audio", 96, "MP4A-LATM/48000/2", map[string]string{
"profile-level-id": "15",
"cpresent": "0",
"config": "400026103fc0",
"sbr-enabled": "1",
})
require.Error(t, err)
_, err = Unmarshal("audio", 96, "MP4A-LATM/48000/2", map[string]string{
"profile-level-id": "15",
"object": "2",
"cpresent": "0",
"sbr-enabled": "1",
})
require.Error(t, err)
}
func FuzzUnmarshalH264(f *testing.F) { func FuzzUnmarshalH264(f *testing.F) {
f.Fuzz(func(t *testing.T, sps string, pktMode string) { f.Fuzz(func(t *testing.T, sps string, pktMode string) {
Unmarshal("video", 96, "H264/90000", map[string]string{ Unmarshal("video", 96, "H264/90000", map[string]string{
@@ -737,19 +790,6 @@ func FuzzUnmarshalLPCM(f *testing.F) {
}) })
} }
func FuzzUnmarshalMPEG4AudioLATM(f *testing.F) {
f.Fuzz(func(t *testing.T, a, b, c, d, e, f string) {
Unmarshal("audio", 96, "MP4A-LATM/48000/2", map[string]string{
"profile-level-id": a,
"bitrate": b,
"object": c,
"cpresent": d,
"config": e,
"sbr-enabled": f,
})
})
}
func FuzzUnmarshalMPEG4VideoES(f *testing.F) { func FuzzUnmarshalMPEG4VideoES(f *testing.F) {
f.Fuzz(func(t *testing.T, a, b string) { f.Fuzz(func(t *testing.T, a, b string) {
Unmarshal("video", 96, "MP4V-ES/90000", map[string]string{ Unmarshal("video", 96, "MP4V-ES/90000", map[string]string{

View File

@@ -6,6 +6,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/bluenviron/mediacommon/pkg/codecs/mpeg4audio"
"github.com/pion/rtp" "github.com/pion/rtp"
) )
@@ -17,7 +18,7 @@ type MPEG4AudioLATM struct {
Channels int Channels int
ProfileLevelID int ProfileLevelID int
Bitrate *int Bitrate *int
Object int Object mpeg4audio.ObjectType
CPresent *bool CPresent *bool
Config []byte Config []byte
SBREnabled *bool SBREnabled *bool
@@ -84,10 +85,18 @@ func (f *MPEG4AudioLATM) unmarshal(
case "object": case "object":
tmp, err := strconv.ParseInt(val, 10, 64) tmp, err := strconv.ParseInt(val, 10, 64)
if err != nil { if err != nil {
return fmt.Errorf("invalid object: %v", val) return fmt.Errorf("invalid object type: %v", val)
} }
f.Object = int(tmp) f.Object = mpeg4audio.ObjectType(int(tmp))
switch f.Object {
case mpeg4audio.ObjectTypeAACLC,
mpeg4audio.ObjectTypeSBR,
mpeg4audio.ObjectTypePS:
default:
return fmt.Errorf("unsupported object type: %d", f.Object)
}
case "cpresent": case "cpresent":
tmp, err := strconv.ParseInt(val, 10, 64) tmp, err := strconv.ParseInt(val, 10, 64)

View File

@@ -1,7 +0,0 @@
go test fuzz v1
string("%20")
string("")
string("oc\x97\xf3V\x8e\xe0")
string("")
string("\x0f\x11")
string("Z")

View File

@@ -1,7 +0,0 @@
go test fuzz v1
string("")
string("")
string("")
string("")
string("")
string("0")

View File

@@ -1,7 +0,0 @@
go test fuzz v1
string("")
string("")
string("oc\x97\xf3V\x8e\xe0")
string("")
string("9A")
string("X")

View File

@@ -1,7 +0,0 @@
go test fuzz v1
string("")
string("")
string("oc\x97\xf3V\x8e\xe0")
string("")
string("\x0f\x11")
string("0")