httptoolkit / xz-decompress

XZ decompression for the browser & Node without native code, via WebAssembly
6 stars 2 forks source link

Document `xz-embedded` limitations and/or improve error messaging #2

Open ariofrio opened 1 year ago

ariofrio commented 1 year ago

I'm getting the following error:

error: Uncaught (in promise) Error: get_next_output failed with error code 7
    at XzContext.getNextOutput (file:///~/Library/Caches/deno/npm/registry.npmjs.org/xz-decompress/0.2.1/dist/package/xz-decompress.js:159:19)
    at Object.pull (file:///~/Library/Caches/deno/npm/registry.npmjs.org/xz-decompress/0.2.1/dist/package/xz-decompress.js:246:50)
    at eventLoopTick (ext:core/01_core.js:183:11)

This was puzzling, and at first I thought it was another issue with WASM compatibility but I looked into the source code and found out the following:

This is an error thrown by the xz-embedded library itself

Error code 7 refers to "XZ_DATA_ERROR: Compressed data is corrupt." It may be good to include descriptive error messages in the Error for ease of troubleshooting. Here are the xz binary's error messages.

The xz-embedded library is pretty limited

/*
 * This is really limited: Not all filters from .xz format are supported,
 * only CRC32 is supported as the integrity check, and decoding of
 * concatenated .xz streams is not supported. Thus, you may want to look
 * at xzdec from XZ Utils if a few KiB bigger tool is not a problem.
 */

For my use case of decompressing CrUX dumps, the problem was that the XZ archives used LZMA2:26 CRC64 (according to 7z l) rather than CRC32. It might be good to reproduce this warning in the README.

pimterry commented 1 year ago

Sure, that makes sense! PRs welcome.