summaryrefslogtreecommitdiff
path: root/libavformat/os_support.c
diff options
context:
space:
mode:
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>2013-03-10 20:03:19 +0100
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>2013-03-16 13:40:36 +0100
commitc3c3bc7ff6b25326800ef6aae3ba46f9de75d3a7 (patch)
tree5459077db6a0397f9147b7ddd7bc8faa0a9de4ac /libavformat/os_support.c
parent23426987fa206833e48f22aa7c80d038c836a196 (diff)
downloadffmpeg-c3c3bc7ff6b25326800ef6aae3ba46f9de75d3a7.tar.gz
Make ff_win32_open more robust.
- 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: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
Diffstat (limited to 'libavformat/os_support.c')
-rw-r--r--libavformat/os_support.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/libavformat/os_support.c b/libavformat/os_support.c
index 15cf753072..0a901f6bd2 100644
--- a/libavformat/os_support.c
+++ b/libavformat/os_support.c
@@ -44,20 +44,23 @@ 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)
+ 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 maybe be in CP_ACP */
+ return _sopen(filename_utf8, oflag, SH_DENYNO, pmode);
}
#endif