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

Clément Bœsch ubitux at gmail.com
Thu Oct 6 01:36:32 CEST 2011


On Thu, Oct 06, 2011 at 01:24:21AM +0200, Clément Bœsch wrote:
> On Thu, Oct 06, 2011 at 12:35:38AM +0200, Michael Niedermayer wrote:
> > On Thu, Oct 06, 2011 at 12:30:53AM +0200, Clément Bœsch wrote:
> > > On Thu, Oct 06, 2011 at 12:22:34AM +0200, Michael Niedermayer wrote:
> > > [...]
> > > > > @@ -67,8 +74,23 @@ static int modplug_read_header(AVFormatContext *s, AVFormatParameters *ap)
> > > > >      AVIOContext *pb = s->pb;
> > > > >      ModPlug_Settings settings;
> > > > >      ModPlugContext *modplug = s->priv_data;
> > > > > +    int sz = avio_size(pb);
> > > > >  
> > > > > -    int sz = avio_read(pb, modplug->buf, sizeof(modplug->buf));
> > > > > +    if (sz < 0) {
> > > > > +        av_log(s, AV_LOG_WARNING, "Could not determine file size\n");
> > > > 
> > > > > +        if (modplug->max_size != FF_MODPLUG_DEF_FILE_SIZE)
> > > > > +            sz = modplug->max_size;
> > > > > +        else
> > > > > +            sz = FF_MODPLUG_DEF_FILE_SIZE;
> > > > 
> > > > sz = modplug->max_size;
> > > > 
> > > 
> > > Indeed…
> > > 
> > > > 
> > > > > +    } else if (modplug->max_size && sz > modplug->max_size) {
> > > > > +        sz = modplug->max_size;
> > > > > +        av_log(s, AV_LOG_WARNING, "Max file size reach%s, allocating %dB\n",
> > > > > +               sz == FF_MODPLUG_DEF_FILE_SIZE ? " (see -max_size)" : "", sz);
> > > > > +    }
> > > > 
> > > > does this work for any file ?
> > > 
> > > No it's likely to fail every time unfortunately.
> > > 
> > > > i would have thought many mod file formats are sensitiv to being
> > > > truncated
> > > 
> > > Yes, it was the case with all the samples I tested (it's the reason the
> > > message mentions the -max_size option to workaround the issue), but I
> > > believe at least one will be OK, so it doesn't fail immediately.
> > > 
> > > Maybe you would prefer an extra warning saying it will likely fail?
> > 
> > yes
> > 
> 
> Added "but demuxing is likely to fail due to incomplete buffer".
> 
> [...]
> 

And with the other changes too…

-- 
Clément B.
-------------- next part --------------
From a3978f80d5e43480491f2bfb7b0c143025819fab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <ubitux at gmail.com>
Date: Wed, 5 Oct 2011 22:47:46 +0200
Subject: [PATCH 2/3] libmodplug: add an option to enlarge the max supported
 file size.

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

diff --git a/libavformat/libmodplug.c b/libavformat/libmodplug.c
index a3c407f..f7f0143 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,13 @@ 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 FF_MODPLUG_DEF_FILE_SIZE (  5 * 1<<20) //   5M
+
 #define OFFSET(x) offsetof(ModPlugContext, x)
 #define D AV_OPT_FLAG_DECODING_PARAM
 static const AVOption options[] = {
@@ -51,6 +56,8 @@ static const AVOption options[] = {
     {"bass_range",      "XBass cutoff in Hz 10-100",            OFFSET(bass_range),      FF_OPT_TYPE_INT, {.dbl = 0}, 0,     100, D},
     {"surround_depth",  "Surround level 0(quiet)-100(heavy)",   OFFSET(surround_depth),  FF_OPT_TYPE_INT, {.dbl = 0}, 0,     100, D},
     {"surround_delay",  "Surround delay in ms, usually 5-40ms", OFFSET(surround_delay),  FF_OPT_TYPE_INT, {.dbl = 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, {.dbl = FF_MODPLUG_DEF_FILE_SIZE}, 0, FF_MODPLUG_MAX_FILE_SIZE, D},
     {NULL},
 };
 
@@ -67,8 +74,21 @@ static int modplug_read_header(AVFormatContext *s, AVFormatParameters *ap)
     AVIOContext *pb = s->pb;
     ModPlug_Settings settings;
     ModPlugContext *modplug = s->priv_data;
+    int sz = avio_size(pb);
 
-    int sz = avio_read(pb, modplug->buf, sizeof(modplug->buf));
+    if (sz < 0) {
+        av_log(s, AV_LOG_WARNING, "Could not determine file size\n");
+        sz = modplug->max_size;
+    } else if (modplug->max_size && sz > modplug->max_size) {
+        sz = modplug->max_size;
+        av_log(s, AV_LOG_WARNING, "Max file size reach%s, allocating %dB "
+               "but demuxing is likely to fail due to incomplete buffer\n",
+               sz == FF_MODPLUG_DEF_FILE_SIZE ? " (see -max_size)" : "", sz);
+    }
+    modplug->buf = av_malloc(modplug->max_size);
+    if (!modplug->buf)
+        return AVERROR(ENOMEM);
+    sz = avio_read(pb, modplug->buf, sz);
 
     ModPlug_GetSettings(&settings);
     settings.mChannels       = 2;
-- 
1.7.7

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20111006/ce16eaa7/attachment.asc>


More information about the ffmpeg-devel mailing list