Skip to content

fix(brotli): better brotli detection heuristics #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2025

Conversation

darkliquid
Copy link
Contributor

Brotli annoyingly lacks magic bits/headers making content-sniffing it quite difficult. We now employ multiple heuristics including:

  • checking for errors reading the first 16 bytes
  • checking to see if the decompressed data exists in the input stream
  • reading in chunks of 16 bytes up until 128 bytes have been read, checking for errors that would indicate a corrupt archive (which we can infer is us actually trying to decompress non-brotli data)

Fixes #29

Also forces update to the latest brotli package commit which includes some relevant fixes as there isn't a new official release tag yet.

Brotli annoyingly lacks magic bits/headers making content-sniffing it
quite difficult. We now employ multiple heuristics including:
- checking for errors reading the first 16 bytes
- checking to see if the decompressed data exists in the input stream
- reading in chunks of 16 bytes up until 128 bytes have been read,
  checking for errors that would indicate a corrupt archive (which we
  can infer is us actually trying to decompress non-brotli data)
Copy link
Owner

@mholt mholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, thanks! Let's give this a shot!

@mholt mholt merged commit 4393d88 into mholt:main Apr 25, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Brotli compression detection is unreliable
2 participants