Skip to main content
Menu
Advisories

Zero-length H264 SPS/PPS in an RTMP AVC configuration causes an unrecovered panic that terminates MediaMTX

GHSA-5JGV-C722-R5CGPublished Updated GitHub

Description

MediaMTX's RTMP server uses gortmplib to detect a publisher's tracks during an initial analysis window of about two seconds. The first H264 AVCDecoderConfigurationRecord creates the track, while any later configuration message is buffered and replayed after the window through the OnDataH264 callback as an access unit made of the first SPS and the first PPS (SequenceParameterSets[0] and PictureParameterSets[0]). The parsing code only verified that the SPS and PPS counts were non-zero, not that the NAL units themselves contained any data. The H265 path was affected in a similar way, since parameter sets were indexed without checking their length.

An unauthenticated RTMP publisher could therefore publish a valid H264 track and then send a second configuration declaring one SPS and one PPS, both with length zero. The empty slices were forwarded unchanged by internal/protocols/rtmp/to_stream.go to SubStream.WriteUnit, which called formatUpdaterH264 in internal/stream/format_updater.go. That function reads the NAL unit type with nalu[0] & 0x1F without checking the length, causing an index out of range [0] with length 0 panic. The panic is not recovered and terminates the whole process, interrupting every stream and every protocol served by the instance. The attack requires a tiny RTMP message and no credentials on any path that allows anonymous publishing.

This was fixed in gortmplib PR #121, which makes the RTMP message parsing and the reader reject empty H264 and H265 parameter sets as malformed input, so that only NAL units with at least 1 byte are passed to the OnDataH26x callbacks and the error is limited to the offending connection. MediaMTX includes the fix since the update of gortmplib to v1.0.2.

Reported by the University of Sydney security research team.

Affected versions

References

GitHub · bluenviron/mediamtx