- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.2k
Call native BrotliEncoderMaxCompressedSize method for BrotliEncoder.GetMaxCompressedLength #108043
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
Conversation
…etMaxCompressedLength
| 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 | 
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than having this hardcoded constant, though, couldn't we just call the native method and then throw ArgumentOutOfRangeException if the result was > int.MaxValue? Part of the point of this change was delegating all behavior to the native function, but we're lifting some of the behavior back up into the C# by hardcoding this constant, which in theory could be invalidated the next time we take a Brotli update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, good point
| /ba-g test failures in  | 
BrotliEncoder.GetMaxCompressedLengthreturns invalid value for some input because managed implementation differs from native Brotli native implementation that updated many years agoAs 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