[FFmpeg-cvslog] img2dec: Recognize glob meta chars only if prefixed by %
Alexander Strasser
git at videolan.org
Fri Mar 30 00:23:54 CEST 2012
ffmpeg | branch: master | Alexander Strasser <eclipse7 at gmx.net> | Sun Mar 11 15:24:51 2012 +0100| [3e1ff8eb27e547c330af72ec87ca75a951d64c24] | committer: Michael Niedermayer
img2dec: Recognize glob meta chars only if prefixed by %
This changes globbing support to only be used if the character
contains at least one glob meta character that is preceded by
an unescaped %. To escape a literal % one would use %% which is
identical to the way to match a % with image2 sequence generation
feature.
* Makes it possible to have patterns like %04d-[720p].jpg work
again with sequence number generation. Previously this would
always be detected as a glob pattern and was interpreted by
the image2 glob code instead.
* Makes it possible to use %*-[720p].jpg to match above pattern
without having to double escape it to be not interpreted by most
shells and not by the image2 glob code (previously one would
need to use \*-\\\[720p\\\].jpg to achieve the same)
Signed-off-by: Alexander Strasser <eclipse7 at gmx.net>
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3e1ff8eb27e547c330af72ec87ca75a951d64c24
---
libavformat/img2dec.c | 30 ++++++++++++++++++++++++++++--
1 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index d10a7a4..155f9fc 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -95,9 +95,19 @@ static int infer_size(int *width_ptr, int *height_ptr, int size)
static int is_glob(const char *path)
{
#if HAVE_GLOB
- size_t span = strcspn(path, "*?[]{}\\");
+ size_t span = 0;
+ const char *p = path;
+
+ while (p = strchr(p, '%')) {
+ if (*(++p) == '%') {
+ ++p;
+ continue;
+ }
+ if (span = strspn(p, "*?[]{}"))
+ break;
+ }
/* Did we hit a glob char or get to the end? */
- return path[span] != '\0';
+ return span != 0;
#else
return 0;
#endif
@@ -222,7 +232,23 @@ static int read_header(AVFormatContext *s1)
s->use_glob = is_glob(s->path);
if (s->use_glob) {
#if HAVE_GLOB
+ char *p = s->path, *q, *dup;
int gerr;
+
+ dup = q = av_strdup(p);
+ while (*q) {
+ /* Do we have room for the next char and a \ insertion? */
+ if ((p - s->path) >= (sizeof(s->path) - 2))
+ break;
+ if (*q == '%' && strspn(q + 1, "%*?[]{}"))
+ ++q;
+ else if (strspn(q, "\\*?[]{}"))
+ *p++ = '\\';
+ *p++ = *q++;
+ }
+ *p = 0;
+ av_free(dup);
+
gerr = glob(s->path, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC|GLOB_TILDE_CHECK, NULL, &s->globstate);
if (gerr != 0) {
return AVERROR(ENOENT);
More information about the ffmpeg-cvslog
mailing list