Commit 29493be5 authored by Julien Muchembled's avatar Julien Muchembled

DMS: fix DoS in image conversion

parent eedee92c
...@@ -335,6 +335,11 @@ class Image(TextConvertableMixin, File, OFSImage): ...@@ -335,6 +335,11 @@ class Image(TextConvertableMixin, File, OFSImage):
parameter_list.append('-') parameter_list.append('-')
if format: if format:
# Is there a way to make 'convert' fail if the format is unknown,
# instead of treating this whole parameter as an output file path?
# As a workaround, we run 'convert' in a non-writeable directory.
if '/' in format or os.access('/', os.W_OK):
raise ConversionError
parameter_list.append('%s:-' % format) parameter_list.append('%s:-' % format)
else: else:
parameter_list.append('-') parameter_list.append('-')
...@@ -350,6 +355,7 @@ class Image(TextConvertableMixin, File, OFSImage): ...@@ -350,6 +355,7 @@ class Image(TextConvertableMixin, File, OFSImage):
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
cwd='/',
close_fds=True) close_fds=True)
try: try:
# XXX: The only portable way is to pass what stdin.write can accept, # XXX: The only portable way is to pass what stdin.write can accept,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment