From 7d1f7ee10a6a71df6e031547a31dc24bd4494e24 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 4 Feb 2014 17:58:23 +0100 Subject: [IMP] handling of overly large images in website image upload bzr revid: xmo@openerp.com-20140204165823-q05aoq83q28b2hhg --- addons/website/controllers/main.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'addons/website/controllers/main.py') diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index b9fc68bb667..0a3f717740f 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -239,13 +239,20 @@ class Website(openerp.addons.web.controllers.main.Home): @http.route('/website/attach', type='http', auth='user', methods=['POST'], website=True) def attach(self, func, upload): - req = request.httprequest url = message = None try: + image_data = upload.read() + image = Image.open(cStringIO.StringIO(image_data)) + w, h = image.size + if w*h > 42e6: # Nokia Lumia 1020 photo resolution + raise ValueError( + u"Image size excessive, uploaded images must be smaller " + u"than 42 million pixel") + attachment_id = request.registry['ir.attachment'].create(request.cr, request.uid, { 'name': upload.filename, - 'datas': upload.read().encode('base64'), + 'datas': image_data.encode('base64'), 'datas_fname': upload.filename, 'res_model': 'ir.ui.view', }, request.context) @@ -259,7 +266,7 @@ class Website(openerp.addons.web.controllers.main.Home): }) except Exception, e: logger.exception("Failed to upload image to attachment") - message = str(e) + message = unicode(e) return """