avformat/rtpenc_h264_hevc: Check space for nal_length_size in ff_rtp_send_h264_hevc()
authorMichael Niedermayer <michael@niedermayer.cc>
Fri, 24 Oct 2025 18:29:23 +0000 (20:29 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Wed, 19 Nov 2025 01:04:59 +0000 (02:04 +0100)
Fixes: memcpy with negative size
Fixes: momo_trip-poc/input

Reported-by: Momoko Shiraishi <shiraishi@os.is.s.u-tokyo.ac.jp>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit d03483bd265b68db00c9b90f6f48dcf61c5c300d)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavformat/rtpenc_h264_hevc.c

index 4d222dca754616c3beec7b8fce6a33fef4ef6dc7..38d508fe8f532d6bc88688c2ed0daf6efdba9521 100644 (file)
@@ -196,6 +196,9 @@ void ff_rtp_send_h264_hevc(AVFormatContext *s1, const uint8_t *buf1, int size)
             r1 = ff_nal_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++));