mirror of
https://github.com/google/brotli.git
synced 2026-07-08 17:56:58 +00:00
Add support for being able to detect a brotli-compressed file? #361
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @juj on GitHub (Nov 10, 2020).
Identifying a gzip-compressed file is super-easy by checking whether the file starts with magic bytes
1Fand8B. (ignoring false positives etc.)It has been discussed before that Brotli is a stream that does not have such magic bytes. That has led to other projects not being able to move forward, such as
fileandlibmagictools not being able to detect Brotli compressed content (#727).There was a proposal for a Brotli framing format at https://github.com/madler/brotli/blob/master/br-format-v3.txt , but if I understand its latest status correctly, it was just a proposal, with no actual plan or possibility to move forward, as it would break binary compatibility with existing Brotli compressed content? (so e.g. Chrome, Firefox and Safari would need to add support for this new framed format?) Is that accurate?
It seems based on #462 and #298 that the request to add a magic number or an official framing was dropped, with no plans to actually go forward with either?
If so, and adding magic numbers and/or official framing is not on the table anymore, I would like to propose an alternative feature that would at least work for some users' use cases, and retain the existing binary compatibility.
Unity is using a mechanism that enables embedding an uncompressed comment string into the Brotli binary. See the local code modification here:
5a6d5d9c7fThat enables a
brotlicompressor to receive a string--comment "UnityWeb Compressed Content (brotli)"on the command line, which gets embedded to the stream. Unity is then using the following JavaScript code in a browser context to detect .br compressed files:Would it be possible for this to become an officially supported feature in the command line executable brotli compressor? E.g. if one runs
that would emit the given comment into the output file. Then users would be able to identify at least their own generated .br files - or if a compressor is used within a certain community (say among Emscripten developers), tooling could be used within that scope to develop detectable .br files?
That way people who oppose adding magic numbers or framing would not have their .br file size increase, but people would still be able to identify their generated .br files.
@polarathene commented on GitHub (May 5, 2021):
AFAIK Dropbox has a port
rust-brotlithat added a magic number feature in Sep 2018.It's meant to be compatible as a C drop-in replacement of this project AFAIK, but I'm not sure if it's been keeping in sync, so it might have diverged a bit. It has a few other additions too.
@eustas commented on GitHub (Jan 4, 2023):
Nice idea. Going to add comment feature soon.
@Artoria2e5 commented on GitHub (Apr 16, 2023):
Comment (or any variable-length part really) is also useful for HTB, the mitigation used to add randomness to packet sizes and mess with the BREACH exploit.
@juj commented on GitHub (May 10, 2023):
Hey @eustas , I wonder if that comment feature got added? Your post above suggests that it would have been something that was favorable to carry upstream?
@eustas commented on GitHub (Jan 11, 2024):
Done. See
--comment=/-CCLI options.