mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-04-27 12:33:41 +03:00
Removed tempfile.mktemp, fixes CVE-2014-1932 CVE-2014-1933, debian bug #737059
This commit is contained in:
parent
b1b88cf4d2
commit
4e9f367dfd
|
@ -67,7 +67,8 @@ def Ghostscript(tile, size, fp, scale=1):
|
||||||
|
|
||||||
import tempfile, os, subprocess
|
import tempfile, os, subprocess
|
||||||
|
|
||||||
file = tempfile.mktemp()
|
out_fd, file = tempfile.mkstemp()
|
||||||
|
os.close(out_fd)
|
||||||
|
|
||||||
# Build ghostscript command
|
# Build ghostscript command
|
||||||
command = ["gs",
|
command = ["gs",
|
||||||
|
|
|
@ -495,13 +495,16 @@ class Image:
|
||||||
self.readonly = 0
|
self.readonly = 0
|
||||||
|
|
||||||
def _dump(self, file=None, format=None):
|
def _dump(self, file=None, format=None):
|
||||||
import tempfile
|
import tempfile, os
|
||||||
if not file:
|
if not file:
|
||||||
file = tempfile.mktemp()
|
f, file = tempfile.mkstemp(format or '')
|
||||||
|
os.close(f)
|
||||||
|
|
||||||
self.load()
|
self.load()
|
||||||
if not format or format == "PPM":
|
if not format or format == "PPM":
|
||||||
self.im.save_ppm(file)
|
self.im.save_ppm(file)
|
||||||
else:
|
else:
|
||||||
|
if file.endswith(format):
|
||||||
file = file + "." + format
|
file = file + "." + format
|
||||||
self.save(file, format)
|
self.save(file, format)
|
||||||
return file
|
return file
|
||||||
|
|
|
@ -172,8 +172,8 @@ class IptcImageFile(ImageFile.ImageFile):
|
||||||
self.fp.seek(offset)
|
self.fp.seek(offset)
|
||||||
|
|
||||||
# Copy image data to temporary file
|
# Copy image data to temporary file
|
||||||
outfile = tempfile.mktemp()
|
o_fd, outfile = tempfile.mkstemp(text=False)
|
||||||
o = open(outfile, "wb")
|
o = os.fdopen(o_fd)
|
||||||
if encoding == "raw":
|
if encoding == "raw":
|
||||||
# To simplify access to the extracted file,
|
# To simplify access to the extracted file,
|
||||||
# prepend a PPM header
|
# prepend a PPM header
|
||||||
|
|
|
@ -344,13 +344,17 @@ class JpegImageFile(ImageFile.ImageFile):
|
||||||
# ALTERNATIVE: handle JPEGs via the IJG command line utilities
|
# ALTERNATIVE: handle JPEGs via the IJG command line utilities
|
||||||
|
|
||||||
import tempfile, os
|
import tempfile, os
|
||||||
file = tempfile.mktemp()
|
f, path = tempfile.mkstemp()
|
||||||
os.system("djpeg %s >%s" % (self.filename, file))
|
os.close(f)
|
||||||
|
if os.path.exists(self.filename):
|
||||||
|
os.system("djpeg '%s' >'%s'" % (self.filename, path))
|
||||||
|
else:
|
||||||
|
raise ValueError("Invalid Filename")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.im = Image.core.open_ppm(file)
|
self.im = Image.core.open_ppm(path)
|
||||||
finally:
|
finally:
|
||||||
try: os.unlink(file)
|
try: os.unlink(path)
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
self.mode = self.im.mode
|
self.mode = self.im.mode
|
||||||
|
|
Loading…
Reference in New Issue
Block a user