From a7c58303ca65e7913997fa006fc87e1d6adb1acb Mon Sep 17 00:00:00 2001 From: Henrique Dante de Almeida Date: Fri, 15 Apr 2016 12:54:47 -0300 Subject: [PATCH] Make ImageFile load images in read-only mode The code path for mmapped files unnecessarily loaded images in read-write mode and had a long standing FIXME message. This patch uses mmap.ACCESS_READ, which is platform independent to fix this issue. --- PIL/ImageFile.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/PIL/ImageFile.py b/PIL/ImageFile.py index 9617ffb3b..6217b2f92 100644 --- a/PIL/ImageFile.py +++ b/PIL/ImageFile.py @@ -163,10 +163,9 @@ class ImageFile(Image.Image): else: # use mmap, if possible import mmap - fp = open(self.filename, "r+") + fp = open(self.filename, "r") size = os.path.getsize(self.filename) - # FIXME: on Unix, use PROT_READ etc - self.map = mmap.mmap(fp.fileno(), size) + self.map = mmap.mmap(fp.fileno(), size, access=mmap.ACCESS_READ) self.im = Image.core.map_buffer( self.map, self.size, d, e, o, a )