A platform for community discussion. Free, open, simple.
FIX: Detect resize failures in the client size image optimization (#13589)
Rafael dos Santos Silva9b51b9bf4e78
diff --git a/public/javascripts/media-optimization-worker.js b/public/javascripts/media-optimization-worker.jsindex 7bd196854c2..9b693e33712 100644--- a/public/javascripts/media-optimization-worker.js+++ b/public/javascripts/media-optimization-worker.js@@ -74,6 +74,9 @@ async function optimize(imageData, fileName, width, height, settings) {settings.resize_pre_multiply,settings.resize_linear_rgb);+ if (resizeResult[3] !== 255) {+ throw "Image corrupted during resize. Falling back to the original for encode"+ }maybeResized = new ImageData(resizeResult,target_dimensions.width,@@ -103,6 +106,10 @@ async function optimize(imageData, fileName, width, height, settings) {logIfDebug(`Worker post reencode file: ${finalSize}`);logIfDebug(`Reduction: ${(initialSize / finalSize).toFixed(1)}x speedup`);+ if (finalSize < 20000) {+ throw "Final size suspciously small, discarding optimizations"+ }+let transferrable = Uint8Array.from(result).buffer; // decoded was allocated inside WASM so it **cannot** be transfered to another context, need to copy by valuereturn transferrable;