[FFmpeg-devel] [PATCH] avformat/assenc: Fix potential NULL + 1

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Tue Mar 14 05:10:35 EET 2023


Incrementing a NULL pointer is undefined behaviour,
yet this is what would happen in case trailer were NULL
before the check.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavformat/assenc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/assenc.c b/libavformat/assenc.c
index 85a1e53371..a75f458023 100644
--- a/libavformat/assenc.c
+++ b/libavformat/assenc.c
@@ -63,8 +63,8 @@ static int write_header(AVFormatContext *s)
         if (trailer)
             trailer = strstr(trailer, "\n");
 
-        if (trailer++) {
-            header_size = (trailer - par->extradata);
+        if (trailer) {
+            header_size = (++trailer - par->extradata);
             ass->trailer_size = par->extradata_size - header_size;
             if (ass->trailer_size)
                 ass->trailer = trailer;
-- 
2.34.1



More information about the ffmpeg-devel mailing list