summaryrefslogtreecommitdiff
path: root/odoo/tools/image.py
diff options
context:
space:
mode:
authorPedro M. Baeza <pedro.baeza@gmail.com>2018-08-27 23:36:33 +0200
committerOlivier Dony <odo@odoo.com>2018-10-03 17:48:01 +0200
commit1be50fdeafcd2b94f7b2f47d6e5bc4b6ebaceadd (patch)
tree4489771b5b5dcf02212a4dfdce4e8c2c80e3a6b5 /odoo/tools/image.py
parent376361c15c8d2be15a2579ffd0432f31d745deb8 (diff)
[ADD] *: support SVG images
Introduce official support for SVG files in the framework, including the following parts: 1. When client-side SVG images are uploaded, the content is displayed until you save using data URI scheme according RFC 2397 [1]. This scheme requires to specify content format. Using hardcoded "image/png" works for all images types except SVG. Type-sniffing is done using "magic byte" detection via the first base64 encode byte, so that the proper data URI scheme can be used. This should not cause SVG-related security problems as the file is displayed through `<img>` tag, which does not allow SVG scripting [2]. 2. Make /web/image controller compatible with SVG 3. Add support for SVG files for company logo, which uses a dedicated controller. 4. Resizing of SVG files is a no-op, as it makes little sense for a vector-based format. We also want to avoid micro-alterations to the SVG document (in "natural" viewport parameters) as we would store multiple copies of the files in the filestore. 5. Because SVG files are inherently dangerous, upload of SVG files is restricted to administrators, either by blocking it directly before saving it in the database (binary fields with attachment=False), or by neutering them to text/plain mimetype (for binary fields with attachment=True) 6. Add tests for the SVG upload cases and for the non-admin uploads. [1] https://tools.ietf.org/html/rfc2397 [2] https://www.w3.org/wiki/SVG_Security Closes #26635
Diffstat (limited to 'odoo/tools/image.py')
-rw-r--r--odoo/tools/image.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/odoo/tools/image.py b/odoo/tools/image.py
index 887ba823b96..24aa56ced17 100644
--- a/odoo/tools/image.py
+++ b/odoo/tools/image.py
@@ -51,7 +51,10 @@ def image_resize_image(base64_source, size=(1024, 1024), encoding='base64', file
"""
if not base64_source:
return False
- if size == (None, None):
+ # Return unmodified content if no resize or we etect first 6 bits of '<'
+ # (0x3C) for SVG documents - This will bypass XML files as well, but it's
+ # harmless for these purposes
+ if size == (None, None) or base64_source[:1] == b'P':
return base64_source
image_stream = io.BytesIO(codecs.decode(base64_source, encoding))
image = Image.open(image_stream)