Dexie.js icon indicating copy to clipboard operation
Dexie.js copied to clipboard

Bug in TSON.finalize, misses chunk starts and ends

Open karlmacklin opened this issue 2 years ago • 1 comments

There is definitely a bug at this position: https://github.com/dexie/Dexie.js/blob/master/addons/dexie-export-import/src/tson.ts#L73

What I do: Export a database with two tables of blobs (one audio and one video). In my example I have three audio blobs and three image blobs. All are different/individual.

What I expect to happen: The correct blobs to be tied to correct rows, to represent my 3 audio and image blobs.

What happens instead: The exported blobs are weird. The three audio blobs turns out to be three identical blobs, and each blob consists of ALL the initial three blobs concatenated together. The three image blobs now consists of three identical images. It is only the first image.

What I've tried instead

I changed the linked code line from: typeSpec.finalize(b, allChunks.slice(b.start, b.end)); to: typeSpec.finalize(b, allChunks.slice(b.data.start, b.data.end));

Why? Well at that point in the code, the b object has a property data that in turns keep the start and end positions.

So what happened in that case?

My three audio blobs were exported correctly! Success!

However.. this somehow corrupted the image data and I cannot pinpoint in what way. They all turn out as corrupt images when trying to view them.

@dfahlander

karlmacklin avatar May 13 '22 20:05 karlmacklin

Thanks a lot for the bug report. Seems this would need some deep dive to resolve. I cannot say that I have loads of time over right now to prioritize it but it should be of such nature so that any skilled developer should be able to resolve it some how.

We're using an older version of typeson library but upgrading it would break backward compability in the file format. However, we're already doing all this finalize thing to workaround typeson's bug in this. Therefore, probably it's just a matter of solving our the code in dexie-export-import source and should not require a change in typeson library.

dfahlander avatar May 23 '22 11:05 dfahlander