Skip to content
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

Call native BrotliEncoderMaxCompressedSize method for BrotliEncoder.GetMaxCompressedLength #108043

Merged
merged 2 commits into from
Oct 8, 2024

Conversation

buyaa-n
Copy link
Member

@buyaa-n buyaa-n commented Sep 19, 2024

BrotliEncoder.GetMaxCompressedLength returns invalid value for some input because managed implementation differs from native Brotli native implementation that updated many years ago

As discussed in the issue we should use the native implementation since it's the source of truth, and this size needs to remain in sync with what the encoder actually does.

Fixes #35142

@@ -11,7 +11,7 @@ internal static partial class BrotliUtils
public const int Quality_Min = 0;
public const int Quality_Default = 4;
public const int Quality_Max = 11;
public const int MaxInputSize = int.MaxValue - 515; // 515 is the max compressed extra bytes
public const int MaxInputSize = int.MaxValue - 524_166; // 524_166 is the max compressed extra bytes
Copy link
Member

Choose a reason for hiding this comment

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

Where does this number come from?

Copy link
Member Author

@buyaa-n buyaa-n Oct 7, 2024

Choose a reason for hiding this comment

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

Before int.MaxValue - 515 = 2_147_483_132 was producing max compressed length, i.e. GetMaxCompressedLength(2_147_483_132)) returned int.MaxValue. Now this produces negative number

After testing with various values now this value equals 524_166 and GetMaxCompressedLength(int.MaxValue - 524_166))producesint.MaxValue`

The comment is not that clear, but do not have a better version

@buyaa-n
Copy link
Member Author

buyaa-n commented Oct 8, 2024

/ba-g test failures in chrome-DebuggerTests are unrelated and has no log (dead-lettered), though there is many issues for same tests probably have same root cause

@buyaa-n buyaa-n merged commit 848cabd into dotnet:main Oct 8, 2024
156 of 161 checks passed
@buyaa-n buyaa-n deleted the max-encode-length branch October 8, 2024 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BrotliEncoder.GetMaxCompressedLength returns invalid value
2 participants