From ad04025987e5c926ae5bde8947a44b3f1346e64c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Sun, 10 Mar 2013 20:03:19 +0100 Subject: [PATCH 1/3] win32: Make ff_win32_open more robust MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Make MultiByteToWideChar fail when it encounters invalid encoding. Without this, invalid characters might just be skipped - When MultiByteToWideChar fails, assume the file name is in CP_ACP and open it via normal open function, even when the file will be written - When malloc fails return error instead of crashing Signed-off-by: Martin Storsjö --- libavformat/os_support.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/libavformat/os_support.c b/libavformat/os_support.c index 1ecf43c3dc..30581ed7c2 100644 --- a/libavformat/os_support.c +++ b/libavformat/os_support.c @@ -33,6 +33,7 @@ #include #include #include +#include int ff_win32_open(const char *filename_utf8, int oflag, int pmode) { @@ -41,20 +42,25 @@ int ff_win32_open(const char *filename_utf8, int oflag, int pmode) wchar_t *filename_w; /* convert UTF-8 to wide chars */ - num_chars = MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, NULL, 0); + num_chars = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filename_utf8, -1, NULL, 0); if (num_chars <= 0) - return -1; + goto fallback; filename_w = av_mallocz(sizeof(wchar_t) * num_chars); + if (!filename_w) { + errno = ENOMEM; + return -1; + } MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, filename_w, num_chars); fd = _wsopen(filename_w, oflag, SH_DENYNO, pmode); av_freep(&filename_w); - /* filename maybe be in CP_ACP */ - if (fd == -1 && !(oflag & O_CREAT)) - return _sopen(filename_utf8, oflag, SH_DENYNO, pmode); + if (fd != -1 || (oflag & O_CREAT)) + return fd; - return fd; +fallback: + /* filename may be be in CP_ACP */ + return _sopen(filename_utf8, oflag, SH_DENYNO, pmode); } #endif From 85a46ad685048f0c389f0f997c6e33e5546d0b3b Mon Sep 17 00:00:00 2001 From: Hendrik Leppkes Date: Tue, 12 Mar 2013 16:45:13 +0100 Subject: [PATCH 2/3] win32: Use 64-bit fstat/lseek variants for MSVC as well MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/os_support.c | 3 +++ libavformat/os_support.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libavformat/os_support.c b/libavformat/os_support.c index 30581ed7c2..2d8a90346a 100644 --- a/libavformat/os_support.c +++ b/libavformat/os_support.c @@ -29,6 +29,9 @@ #if defined(_WIN32) && !defined(__MINGW32CE__) #undef open +#undef lseek +#undef stat +#undef fstat #include #include #include diff --git a/libavformat/os_support.h b/libavformat/os_support.h index c5d3ab4b33..39d4cb6519 100644 --- a/libavformat/os_support.h +++ b/libavformat/os_support.h @@ -31,7 +31,7 @@ #include -#if defined(__MINGW32__) && !defined(__MINGW32CE__) +#if defined(_WIN32) && !defined(__MINGW32CE__) # include # define lseek(f,p,w) _lseeki64((f), (p), (w)) # define stat _stati64 From cf53704c55378cc0dcfc16637cdac7d58f0b3107 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 12 Mar 2013 18:23:27 +0100 Subject: [PATCH 3/3] AVOptions: make av_set_options_string() forward options to child objects --- libavutil/opt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavutil/opt.c b/libavutil/opt.c index f3dcdeebf8..2cc6f6ce34 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -573,7 +573,7 @@ static int parse_key_value_pair(void *ctx, const char **buf, av_log(ctx, AV_LOG_DEBUG, "Setting value '%s' for key '%s'\n", val, key); - ret = av_opt_set(ctx, key, val, 0); + ret = av_opt_set(ctx, key, val, AV_OPT_SEARCH_CHILDREN); if (ret == AVERROR_OPTION_NOT_FOUND) av_log(ctx, AV_LOG_ERROR, "Key '%s' not found.\n", key);