Skip to content

Commit

Permalink
Removed tempfile.mktemp, fixes CVE-2014-1932 CVE-2014-1933, debian bu…
Browse files Browse the repository at this point in the history
…g #737059
  • Loading branch information
wiredfool committed Mar 14, 2014
1 parent b1b88cf commit 4e9f367
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion PIL/EpsImagePlugin.py
Expand Up @@ -67,7 +67,8 @@ def Ghostscript(tile, size, fp, scale=1):

import tempfile, os, subprocess

file = tempfile.mktemp()
out_fd, file = tempfile.mkstemp()
os.close(out_fd)

# Build ghostscript command
command = ["gs",
Expand Down
9 changes: 6 additions & 3 deletions PIL/Image.py
Expand Up @@ -495,14 +495,17 @@ def _copy(self):
self.readonly = 0

def _dump(self, file=None, format=None):
import tempfile
import tempfile, os
if not file:
file = tempfile.mktemp()
f, file = tempfile.mkstemp(format or '')
os.close(f)

self.load()
if not format or format == "PPM":
self.im.save_ppm(file)
else:
file = file + "." + format
if file.endswith(format):
file = file + "." + format
self.save(file, format)
return file

Expand Down
4 changes: 2 additions & 2 deletions PIL/IptcImagePlugin.py
Expand Up @@ -172,8 +172,8 @@ def load(self):
self.fp.seek(offset)

# Copy image data to temporary file
outfile = tempfile.mktemp()
o = open(outfile, "wb")
o_fd, outfile = tempfile.mkstemp(text=False)
o = os.fdopen(o_fd)
if encoding == "raw":
# To simplify access to the extracted file,
# prepend a PPM header
Expand Down
12 changes: 8 additions & 4 deletions PIL/JpegImagePlugin.py
Expand Up @@ -344,13 +344,17 @@ def load_djpeg(self):
# ALTERNATIVE: handle JPEGs via the IJG command line utilities

import tempfile, os
file = tempfile.mktemp()
os.system("djpeg %s >%s" % (self.filename, file))
f, path = tempfile.mkstemp()
os.close(f)
if os.path.exists(self.filename):
os.system("djpeg '%s' >'%s'" % (self.filename, path))
else:
raise ValueError("Invalid Filename")

try:
self.im = Image.core.open_ppm(file)
self.im = Image.core.open_ppm(path)
finally:
try: os.unlink(file)
try: os.unlink(path)
except: pass

self.mode = self.im.mode
Expand Down

0 comments on commit 4e9f367

Please sign in to comment.