Skip to content

fix(brotli): better brotli detection heuristics#30

Merged
mholt merged 1 commit intomholt:mainfrom
darkliquid:fix-29
Apr 25, 2025
Merged

fix(brotli): better brotli detection heuristics#30
mholt merged 1 commit intomholt:mainfrom
darkliquid:fix-29

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