JavaScript throws Corrupted reserved bit #465

Closed
opened 2026-01-29 20:44:19 +00:00 by claunia · 6 comments
Owner

Originally created by @ijjy on GitHub (Jul 4, 2023).

I'm making my own web application which based on html + js + wasm (created by emscripten). I want to compress my wasm to br and decompress br before loading wasm. I use Mac Terminal to compress wasm.
brotli -o *.wasm.br *wasm
While I use decode.js to decode content of br file, I get the error 'Corrupted reserved bit'. (Actually, I tried both decode.js and decode.min.js) I'm sure the content of the Int8ArrayBuffer I pass to BrotliDecode is correct (i.e. matches the content of br file).
If I use brotli -d -o *.wasm *.wasm.br to decode br file, the output matches wasm file that I compressed.
What should I do?

Originally created by @ijjy on GitHub (Jul 4, 2023). I'm making my own web application which based on html + js + wasm (created by emscripten). I want to compress my wasm to br and decompress br before loading wasm. I use Mac Terminal to compress wasm. `brotli -o *.wasm.br *wasm` While I use decode.js to decode content of br file, I get the error 'Corrupted reserved bit'. (Actually, I tried both decode.js and decode.min.js) I'm sure the content of the Int8ArrayBuffer I pass to BrotliDecode is correct (i.e. matches the content of br file). If I use `brotli -d -o *.wasm *.wasm.br` to decode br file, the output matches wasm file that I compressed. What should I do?
Author
Owner

@eustas commented on GitHub (Jul 4, 2023):

Hi. Could you attach compressed file, so that I could debug the decoder.

@eustas commented on GitHub (Jul 4, 2023): Hi. Could you attach compressed file, so that I could debug the decoder.
Author
Owner

@ijjy commented on GitHub (Jul 4, 2023):

Hi. Could you attach compressed file, so that I could debug the decoder.

MyCppStatic.wasm.br.zip
Here is it. Unzip before you debug.

@ijjy commented on GitHub (Jul 4, 2023): > Hi. Could you attach compressed file, so that I could debug the decoder. [MyCppStatic.wasm.br.zip](https://github.com/google/brotli/files/11948486/MyCppStatic.wasm.br.zip) Here is it. Unzip before you debug.
Author
Owner

@eustas commented on GitHub (Jul 4, 2023):

Thanks, will take a look soon.

@eustas commented on GitHub (Jul 4, 2023): Thanks, will take a look soon.
Author
Owner

@eustas commented on GitHub (Jul 4, 2023):

Likely compressed data is corrupted somewhere before decoding.
Attaching demo that decoding works OK: data.js is your .br file encoded as base64, index.html is "main" and decode.js is decoder from trunk.
test.zip

@eustas commented on GitHub (Jul 4, 2023): Likely compressed data is corrupted somewhere before decoding. Attaching demo that decoding works OK: `data.js` is your `.br` file encoded as base64, `index.html` is "main" and `decode.js` is decoder from trunk. [test.zip](https://github.com/google/brotli/files/11949362/test.zip)
Author
Owner

@ijjy commented on GitHub (Jul 5, 2023):

Likely compressed data is corrupted somewhere before decoding.
Attaching demo that decoding works OK: data.js is your .br file encoded as base64, index.html is "main" and decode.js is decoder from trunk.
test.zip

Thank you! It works!
Still, I have 2 questions:

  1. If my .br file is corrupted, how does terminal command decode it?
  2. Could you please tell me how you encode .br file as base64? Do you make any change to .br file? (Ok,I encode .br file by myself and get the same data content.) It's weird that data is corrupted when fetching from a file. I think it's a bug about my js code.
@ijjy commented on GitHub (Jul 5, 2023): > Likely compressed data is corrupted somewhere before decoding. > Attaching demo that decoding works OK: `data.js` is your `.br` file encoded as base64, `index.html` is "main" and `decode.js` is decoder from trunk. > [test.zip](https://github.com/google/brotli/files/11949362/test.zip) Thank you! It works! Still, I have 2 questions: 1. If my .br file is corrupted, how does terminal command decode it? 2. Could you please tell me how you encode .br file as base64? Do you make any change to .br file? (Ok,I encode .br file by myself and get the same data content.) It's weird that data is corrupted when fetching from a file. I think it's a bug about my js code.
Author
Owner

@eustas commented on GitHub (Jul 5, 2023):

As I've said, data is corrupted somewhere before decoding. br file you've shared is fine.

To convert it to base64 I run base64 -w 0 -i input-file.br > output-file.js and then frame output with variable declaration. But, of course, it makes file 1.33x larger.

@eustas commented on GitHub (Jul 5, 2023): As I've said, data is corrupted **somewhere before** decoding. `br` file you've shared is fine. To convert it to base64 I run `base64 -w 0 -i input-file.br > output-file.js` and then frame output with variable declaration. But, of course, it makes file 1.33x larger.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/brotli#465