Skip to content

Commit e76d030

Browse files
ClearlyClairehiyuki2578
authored andcommitted
Fix image uploads being perfectly white when canvas read access is blocked (mastodon#11499)
Fixes mastodon#11496
1 parent 61ed2be commit e76d030

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

app/javascript/mastodon/utils/resize_image.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ const processImage = (img, { width, height, orientation, type = 'image/png' }) =
6767

6868
context.drawImage(img, 0, 0, width, height);
6969

70+
// The Tor Browser and maybe other browsers may prevent reading from canvas
71+
// and return an all-white image instead. Assume reading failed if the resized
72+
// image is perfectly white.
73+
const imageData = context.getImageData(0, 0, width, height);
74+
if (imageData.every(value => value === 255)) {
75+
throw 'Failed to read from canvas';
76+
}
77+
7078
canvas.toBlob(resolve, type);
7179
});
7280

0 commit comments

Comments
 (0)