[FFmpeg-cvslog] avutil/file: fix av_file_map file mapping on Windows

Kacper Michajłow git at videolan.org
Sun Dec 15 16:16:31 EET 2024


ffmpeg | branch: master | Kacper Michajłow <kasper93 at gmail.com> | Mon Dec  9 20:20:02 2024 +0100| [92deed973206ce2ffeea843e0584151476365012] | committer: Anton Khirnov

avutil/file: fix av_file_map file mapping on Windows

This makes the behavior of av_file_map() the same on Windows as it is on
other platforms. The file is opened as read-only, but the mapping is
copy-on-write, allowing the user to write to the memory pages returned
by av_file_map().

This commit fixes libavutil\tests\file.c test, which would crash when
trying to write to a read-only memory page.

Signed-off-by: Kacper Michajłow <kasper93 at gmail.com>
Signed-off-by: Anton Khirnov <anton at khirnov.net>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=92deed973206ce2ffeea843e0584151476365012
---

 libavutil/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavutil/file.c b/libavutil/file.c
index db8507286b..4ef940a6c3 100644
--- a/libavutil/file.c
+++ b/libavutil/file.c
@@ -112,7 +112,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
             return -1;
         }
 
-        ptr = MapViewOfFile(mh, FILE_MAP_READ, 0, 0, *size);
+        ptr = MapViewOfFile(mh, FILE_MAP_COPY, 0, 0, *size);
         CloseHandle(mh);
         if (!ptr) {
             av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in MapViewOfFile()\n");



More information about the ffmpeg-cvslog mailing list