-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
BrotliEncoder.GetMaxCompressedLength returns invalid value #35142
Comments
Tagging subscribers to this area: |
Just hit this one in my code, can confirm. I'm getting a compressed buffer (using |
Interested in debugging some @lcsondes ? |
@danmosemsft What do you need? |
@lcsondes it may be some time before someone can take a look, so sometimes I ask folks whether they’re interested in investigating to figure out the root cause. |
From skimming the source my best guess is this line hardcoding the largest possible large block size while the BrotliEncoder constructor lets you select any window size. The guesswork here is whether the two are related, RFC 7932 doesn't seem to talk about large blocks but it does mention meta-blocks that have a variable size which just so happens to range between 0 and 16M and its header contains the size of the window so there could be a connection. On the other hand if I take my input size which is 4M, 4M>>24 is 0 (which also looks incorrect BTW, surely there must be at least one block if the input is meaningful?) but that only explains 4 bytes of difference. The most I've observed was 6. |
I've encounted same issue. int BrotliEncoderMaxCompressedSize(int input_size)
{
var num_large_blocks = input_size >> 14;
var overhead = 2 + (4 * num_large_blocks) + 3 + 1;
var result = input_size + overhead;
if (input_size == 0) return 2;
return (result < input_size) ? 0 : result;
} My test data,
I think this is a critical issue of compression library, could you fix it? |
@carlossanlop |
For the poor souls who are still affected by this, I recommend switching over to zstd, which is unaffected by this bug, and generally has a better runtime performance and compression ratio. It's unlikely that this one will be fixed in anytime soon, it's been open for more than 3 years. |
.NET 9 RC1 supports new BrotliCompressionOptions in #105430 , however this bug is not cared, |
That was not about for fixing this issue. Anyway the managed implementation of Question is how to fix it:
|
Let's just P/Invoke to the native implementation, since it's the source of truth, and this size needs to remain in sync with what the encoder actually does. |
@buyaa-n you marked this as |
No, it's regression from several releases, just there were no other label with |
It was introduced with .NET Core 3.0 judging by the mentioned brotli 1.0.5 update in 2018. I'm also surprised the milestone was set to .NET 10 considering this is a fix, not a new feature. |
Currently all PRs should go to main (10.0), based on the customer feedback and the risk of the fix management will decide if we port the fix to previous versions and which versions will get fixed |
Project target: netcoreapp3.1
Test code
dotnet --info
The text was updated successfully, but these errors were encountered: