Bug 240216 - Safari corrupts already-rendered blobs after saving to IndexedDB
Summary: Safari corrupts already-rendered blobs after saving to IndexedDB
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Website Storage (show other bugs)
Version: Safari 15
Hardware: Mac (Intel) macOS 12
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-05-08 09:38 PDT by Micah
Modified: 2022-06-08 23:13 PDT (History)
6 users (show)

See Also:


Attachments
Exported codepen (use dist folder) (9.07 KB, application/zip)
2022-05-08 09:38 PDT, Micah
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Micah 2022-05-08 09:38:33 PDT
Created attachment 459014 [details]
Exported codepen (use dist folder)

At befunky.com, we save image Blobs in IndexedDB so we can recover a user's photo editing progress if WebGL crashes. This often fails for returning users in Safari, and we finally figured out why.

Here are the exact steps to take to reproduce:

1. Save an image Blob in IndexedDB
2. Reload the page
3. Grab that image Blob and render it to a canvas (e.g. via  + ObjectURL)
4. Save the image Blob in IndexedDB again.

(sometimes) Repeat steps 2-4
You'll eventually reach a state where the image blob from IndexedDB cannot be read by FileReader, even though it has correct properties otherwise (e.g. size). To consistently replicate, it's important that:

- The page is refreshed between saving & getting blob
- The blob is rendered to Canvas before saving
- The blob is saved over itself (same IndexedDB key)

This is a bit tricky to replicate, so I created a reduced-test-case in a Codepen.
https://codepen.io/pranksinatra/pen/MWjRZOq?editors=1010

Alternative, you can download the attached zip file (use dist) folder to replicate on your local machine, or download it here:
https://codepen-api-export-production.s3.us-west-2.amazonaws.com/zip/PEN/MWjRZOq/1611347502267/safari-indexeddb-blob-bug.zip

Really appreciate the Safari/Webkit team looking into this. We've tried for years to pin down this issue and it causes a lot of user pain!

The original WebCompat report is here: https://github.com/webcompat/web-bugs/issues/66063#issuecomment-765870592
Comment 1 Radar WebKit Bug Importer 2022-05-09 14:45:01 PDT
<rdar://problem/92987277>