[FFmpeg-devel] [PATCH 2/2] libmodplug: add an option to enlarge the max supported file size.

Clément Bœsch ubitux at gmail.com
Wed Oct 5 22:49:44 CEST 2011


---
 libavformat/libmodplug.c |   24 ++++++++++++++++++++++--
 1 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/libavformat/libmodplug.c b/libavformat/libmodplug.c
index 2f7c4fa..a9aa5a6 100644
--- a/libavformat/libmodplug.c
+++ b/libavformat/libmodplug.c
@@ -29,7 +29,7 @@
 typedef struct ModPlugContext {
     const AVClass *class;
     ModPlugFile *f;
-    uint8_t buf[5 * 1<<20]; ///< input file content, 5M max
+    uint8_t *buf; ///< input file content
 
     /* options */
     int noise_reduction;
@@ -39,8 +39,12 @@ typedef struct ModPlugContext {
     int bass_range;
     int surround_depth;
     int surround_delay;
+
+    int max_size; ///< max file size to allocate
 } ModPlugContext;
 
+#define FF_MODPLUG_MAX_FILE_SIZE (100 * 1<<20) // 100M
+
 #define OFFSET(x) offsetof(ModPlugContext, x)
 #define D AV_OPT_FLAG_DECODING_PARAM
 static const AVOption options[] = {
@@ -51,6 +55,8 @@ static const AVOption options[] = {
     {"bass_range",      "XBass cutoff in Hz 10-100",            OFFSET(bass_range),      FF_OPT_TYPE_INT, {.i64 = 0}, 0,     100, D},
     {"surround_depth",  "Surround level 0(quiet)-100(heavy)",   OFFSET(surround_depth),  FF_OPT_TYPE_INT, {.i64 = 0}, 0,     100, D},
     {"surround_delay",  "Surround delay in ms, usually 5-40ms", OFFSET(surround_delay),  FF_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, D},
+    {"max_size",        "Max file size supported (in bytes). Default is 5MB. Set to 0 for no limit (not recommended)",
+     OFFSET(max_size), FF_OPT_TYPE_INT, {.i64 = 5 * 1<<20}, 0, FF_MODPLUG_MAX_FILE_SIZE, D},
     {NULL},
 };
 
@@ -67,8 +73,22 @@ static int modplug_read_header(AVFormatContext *s, AVFormatParameters *ap)
     AVIOContext *pb = s->pb;
     ModPlug_Settings settings;
     ModPlugContext *modplug = s->priv_data;
+    int r, sz = 0;
 
-    int sz = avio_read(pb, modplug->buf, sizeof(modplug->buf));
+    for (;;) {
+        uint8_t *p = av_realloc(modplug->buf, sz + 1024);
+        if (!p) {
+            av_freep(&modplug->buf);
+            return AVERROR(ENOMEM);
+        }
+        modplug->buf = p;
+        r = avio_read(pb, modplug->buf + sz, 1024);
+        if (r == AVERROR_EOF)
+            break;
+        sz += r;
+        if (modplug->max_size && sz >= modplug->max_size)
+            break;
+    }
 
     ModPlug_GetSettings(&settings);
     settings.mChannels       = 2;
-- 
1.7.7



More information about the ffmpeg-devel mailing list