[FFmpeg-devel] [PATCH] Fix issue when invalid nb_index_entries value is read - SPONSORED BY INA (Institut National de l'Audiovisuel)

Cédric Le Barz clebarz at ektacom.com
Wed Mar 8 17:55:27 EET 2023


Fix issue when invalid nb_index_entries value is read : in case of false 
nb_index_entries value, ffmpeg exit. This patch fix this problem.


Signed-off-by: Cedric Le Barz <clebarz at ektacom.com>
---
  ffmpeg/libavformat/mxfdec.c | 14 ++++++++++++--
  1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/ffmpeg/libavformat/mxfdec.c b/ffmpeg/libavformat/mxfdec.c
index 4530617..ffc8987 100644
--- a/ffmpeg/libavformat/mxfdec.c
+++ b/ffmpeg/libavformat/mxfdec.c
@@ -1221,8 +1221,18 @@ static int mxf_read_index_entry_array(AVIOContext 
*pb, MXFIndexTableSegment *seg
      }
       for (i = 0; i < segment->nb_index_entries; i++) {
-        if(avio_feof(pb))
-            return AVERROR_INVALIDDATA;
+
+        if(avio_feof(pb)) {
+            if (i == 0) {
+                return AVERROR_INVALIDDATA;
+            } else {
+                /* To be more robust to invalid nb_index_entries value,
+                   fix the index entry number according to read entries */
+                segment->nb_index_entries = i;
+                return 0;
+            }
+        }
+
          segment->temporal_offset_entries[i] = avio_r8(pb);
          avio_r8(pb);                                        /* 
KeyFrameOffset */
          segment->flag_entries[i] = avio_r8(pb);
-- 
2.34.1



More information about the ffmpeg-devel mailing list