FIX: Detect resize failures in the client size image optimization (PR #13589)

On iOS 15 beta, if you select the camera app when uploading an image and try to upload a freshly taken picture, from the second picture onwards the resize WASM operation will return an array filled with zeroes.

Since every 4th byte is alpha, and at this step we are only dealing with non-transparent images this a O(1) way to detect that the bug was hit. (On normal images, all 4th bytes are 255 at this point)

Also adds a “catch-all” when the original image became too small to try to accomodate other bugs of the same type. By default we only trigger this whole operation on images over 1MB, so if the end result is <20KB something weird did happen. Throwing here will let the upload continue using the original file, so nothing is lost and the user can continue.

GitHub