mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 23:26:54 +08:00
improve check on H264 padding (#559)
This commit is contained in:
@@ -29,6 +29,15 @@ func joinFragments(fragments [][]byte, size int) []byte {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isAllZero(buf []byte) bool {
|
||||||
|
for _, b := range buf {
|
||||||
|
if b != 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// Decoder is a RTP/H264 decoder.
|
// Decoder is a RTP/H264 decoder.
|
||||||
// Specification: https://datatracker.ietf.org/doc/html/rfc6184
|
// Specification: https://datatracker.ietf.org/doc/html/rfc6184
|
||||||
type Decoder struct {
|
type Decoder struct {
|
||||||
@@ -125,8 +134,8 @@ func (d *Decoder) decodeNALUs(pkt *rtp.Packet) ([][]byte, error) {
|
|||||||
size := uint16(payload[0])<<8 | uint16(payload[1])
|
size := uint16(payload[0])<<8 | uint16(payload[1])
|
||||||
payload = payload[2:]
|
payload = payload[2:]
|
||||||
|
|
||||||
// avoid final padding
|
// discard padding
|
||||||
if size == 0 {
|
if size == 0 && isAllZero(payload) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
pkg/format/rtph264/testdata/fuzz/FuzzDecoder/3b0600afabf53c93
vendored
Normal file
3
pkg/format/rtph264/testdata/fuzz/FuzzDecoder/3b0600afabf53c93
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
go test fuzz v1
|
||||||
|
[]byte("0")
|
||||||
|
[]byte("8\x00\x000")
|
@@ -75,10 +75,6 @@ func (d *Decoder) decodeNALUs(pkt *rtp.Packet) ([][]byte, error) {
|
|||||||
size := uint16(payload[0])<<8 | uint16(payload[1])
|
size := uint16(payload[0])<<8 | uint16(payload[1])
|
||||||
payload = payload[2:]
|
payload = payload[2:]
|
||||||
|
|
||||||
if size == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if int(size) > len(payload) {
|
if int(size) > len(payload) {
|
||||||
return nil, fmt.Errorf("invalid aggregation unit (invalid size)")
|
return nil, fmt.Errorf("invalid aggregation unit (invalid size)")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user