From: ThibG Date: Tue, 6 Aug 2019 10:08:19 +0000 (+0200) Subject: Fix image uploads being perfectly white when canvas read access is blocked (#11499) X-Git-Url: https://git.xn--scling-oua.cat.family/?a=commitdiff_plain;h=111a0628fc161df4d76967d7dc7116b8a43fe8e2;p=mastodon.git Fix image uploads being perfectly white when canvas read access is blocked (#11499) Fixes #11496 --- diff --git a/app/javascript/mastodon/utils/resize_image.js b/app/javascript/mastodon/utils/resize_image.js index bbdbc865e..a8ec5f3fa 100644 --- a/app/javascript/mastodon/utils/resize_image.js +++ b/app/javascript/mastodon/utils/resize_image.js @@ -67,6 +67,14 @@ const processImage = (img, { width, height, orientation, type = 'image/png' }) = context.drawImage(img, 0, 0, width, height); + // The Tor Browser and maybe other browsers may prevent reading from canvas + // and return an all-white image instead. Assume reading failed if the resized + // image is perfectly white. + const imageData = context.getImageData(0, 0, width, height); + if (imageData.every(value => value === 255)) { + throw 'Failed to read from canvas'; + } + canvas.toBlob(resolve, type); });