Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix panic when checking pts = dts on H265 (bluenviron/mediamtx#3754) #617

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/format/h264_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,9 @@ func FuzzUnmarshalH264(f *testing.F) {
}
})
}

func FuzzH264PTSEqualsDTS(f *testing.F) {
f.Fuzz(func(t *testing.T, b []byte) {
(&H264{}).PTSEqualsDTS(&rtp.Packet{Payload: b})
})
}
12 changes: 8 additions & 4 deletions pkg/format/h265.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ func (f *H265) PTSEqualsDTS(pkt *rtp.Packet) bool {
return true

case h265.NALUType_AggregationUnit:
if len(pkt.Payload) < 4 {
return false
}

payload := pkt.Payload[2:]

for {
if len(payload) < 2 {
return false
}

size := uint16(payload[0])<<8 | uint16(payload[1])
payload = payload[2:]

Expand All @@ -167,6 +167,10 @@ func (f *H265) PTSEqualsDTS(pkt *rtp.Packet) bool {
if len(payload) == 0 {
break
}

if len(payload) < 2 {
return false
}
}

case h265.NALUType_FragmentationUnit:
Expand Down
6 changes: 6 additions & 0 deletions pkg/format/h265_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,9 @@ func FuzzUnmarshalH265(f *testing.F) {
}
})
}

func FuzzH265PTSEqualsDTS(f *testing.F) {
f.Fuzz(func(t *testing.T, b []byte) {
(&H265{}).PTSEqualsDTS(&rtp.Packet{Payload: b})
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("800")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("\xbc")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("8")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("\xbc\xa8")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("\xbc0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("8\x00\x010")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("8\x00\x01%")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("A")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("b0\xd3")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("a0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("a0\x00\x040000")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("a")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("b00")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("a0\x00\x04A000")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("a000")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("a0\x00\x0100")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("b0")
Loading