Fix panic on AVCCToCodec #1652

This commit is contained in:
Alex X
2025-05-22 15:52:10 +03:00
parent 7107508286
commit ae8145f266
2 changed files with 16 additions and 5 deletions

View File

@@ -82,7 +82,15 @@ func AVCCToCodec(avcc []byte) *core.Codec {
buf := bytes.NewBufferString("packetization-mode=1")
for {
n := len(avcc)
if n < 4 {
break
}
size := 4 + int(binary.BigEndian.Uint32(avcc))
if n < size {
break
}
switch NALUType(avcc) {
case NALUTypeSPS:
@@ -95,11 +103,7 @@ func AVCCToCodec(avcc []byte) *core.Codec {
buf.WriteString(base64.StdEncoding.EncodeToString(avcc[4:size]))
}
if size < len(avcc) {
avcc = avcc[size:]
} else {
break
}
avcc = avcc[size:]
}
return &core.Codec{

View File

@@ -101,3 +101,10 @@ func TestDecodeSPS2(t *testing.T) {
require.Equal(t, uint16(640), sps.Width())
require.Equal(t, uint16(360), sps.Height())
}
func TestAVCCToCodec(t *testing.T) {
s := "000000196764001fac2484014016ec0440000003004000000c23c60c920000000568ee32c8b0000000d365"
b, _ := hex.DecodeString(s)
codec := AVCCToCodec(b)
require.Equal(t, "packetization-mode=1;profile-level-id=64001f;sprop-parameter-sets=Z2QAH6wkhAFAFuwEQAAAAwBAAAAMI8YMkg==,aO4yyLA=", codec.FmtpLine)
}