[FFmpeg-cvslog] avformat/imf_cpl: do not use filesize when reading XML file

Marton Balint git at videolan.org
Fri Apr 1 13:50:20 EEST 2022


ffmpeg | branch: release/5.0 | Marton Balint <cus at passwd.hu> | Tue Feb  1 00:08:22 2022 +0100| [07d953187bb5842241516392b685c43d5768103c] | committer: Zane van Iperen

avformat/imf_cpl: do not use filesize when reading XML file

Similar to the earlier patch applied to imfdec.

Signed-off-by: Marton Balint <cus at passwd.hu>
(cherry picked from commit 8a9d3d3dec74568a1a7f226dab3a779cd0bfc079)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=07d953187bb5842241516392b685c43d5768103c
---

 libavformat/imf_cpl.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/libavformat/imf_cpl.c b/libavformat/imf_cpl.c
index f2ad9c05d6..102a6b4549 100644
--- a/libavformat/imf_cpl.c
+++ b/libavformat/imf_cpl.c
@@ -797,13 +797,11 @@ int ff_imf_parse_cpl(AVIOContext *in, FFIMFCPL **cpl)
     AVBPrint buf;
     xmlDoc *doc = NULL;
     int ret = 0;
-    int64_t filesize = 0;
 
-    filesize = avio_size(in);
-    filesize = filesize > 0 ? filesize : 8192;
-    av_bprint_init(&buf, filesize + 1, AV_BPRINT_SIZE_UNLIMITED);
-    ret = avio_read_to_bprint(in, &buf, UINT_MAX - 1);
-    if (ret < 0 || !avio_feof(in) || buf.len == 0) {
+    av_bprint_init(&buf, 0, INT_MAX); // xmlReadMemory uses integer length
+
+    ret = avio_read_to_bprint(in, &buf, SIZE_MAX);
+    if (ret < 0 || !avio_feof(in)) {
         av_log(NULL, AV_LOG_ERROR, "Cannot read IMF CPL\n");
         if (ret == 0)
             ret = AVERROR_INVALIDDATA;
@@ -812,8 +810,7 @@ int ff_imf_parse_cpl(AVIOContext *in, FFIMFCPL **cpl)
 
     LIBXML_TEST_VERSION
 
-    filesize = buf.len;
-    doc = xmlReadMemory(buf.str, filesize, NULL, NULL, 0);
+    doc = xmlReadMemory(buf.str, buf.len, NULL, NULL, 0);
     if (!doc) {
         av_log(NULL,
                 AV_LOG_ERROR,



More information about the ffmpeg-cvslog mailing list