loro-dev / loro

Make your JSON data collaborative and version-controlled with CRDTs
https://loro.dev
MIT License
4.18k stars 76 forks source link

Handle corrupted bytes data when import. #560

Open timeswind opened 5 hours ago

timeswind commented 5 hours ago

Currently when import any binary data, loro would throw error as Uncaught Decode error: (Invalid magic bytes). How would loro planning to support data repair if some bytes were corrupted?

zxch3n commented 4 hours ago

This is expected behavior. Loro can only be used to import binary content that was exported from Loro, not to import arbitrary binary content.

If some bytes are corrupted, the best approach is to prevent users from importing rather than attempting to fix it. If you want to support error correction, you can wrap it in an additional layer externally, such as using error-correcting codes. If you forcefully import content based on corrupted data interpretation, it will put the document into a state of hidden corruption.

timeswind commented 4 hours ago

@zxch3n Is there way to detect if the byte are correct for loro data struct?

zxch3n commented 4 hours ago

Yeah, every time import is called, Loro will perform the integrity check. Alternatively, you can use decodeImportBlobMeta(blob: Uint8Array, check_integrity: boolean)