From b75fcac83c9444884d919b8673591315ec43eb83 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Fri, 24 Oct 2025 20:29:23 +0200 Subject: [PATCH] avformat/rtpenc_h264_hevc: Check space for nal_length_size in ff_rtp_send_h264_hevc() Fixes: memcpy with negative size Fixes: momo_trip-poc/input Reported-by: Momoko Shiraishi Signed-off-by: Michael Niedermayer (cherry picked from commit d03483bd265b68db00c9b90f6f48dcf61c5c300d) Signed-off-by: Michael Niedermayer --- libavformat/rtpenc_h264_hevc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavformat/rtpenc_h264_hevc.c b/libavformat/rtpenc_h264_hevc.c index 0c88fc2a23..470430478b 100644 --- a/libavformat/rtpenc_h264_hevc.c +++ b/libavformat/rtpenc_h264_hevc.c @@ -195,6 +195,9 @@ void ff_rtp_send_h264_hevc(AVFormatContext *s1, const uint8_t *buf1, int size) r1 = ff_avc_mp4_find_startcode(r, end, s->nal_length_size); if (!r1) r1 = end; + // Check that the last is not truncated + if (r1 - r < s->nal_length_size) + break; r += s->nal_length_size; } else { while (!*(r++));