Skip to content

Commit

Permalink
Validate CompressionLevel in BrotliStream ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
i3arnon committed Aug 15, 2021
1 parent ec07ac8 commit a09b915
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal static partial class BrotliUtils
public const int WindowBits_Default = 22;
public const int WindowBits_Max = 24;
public const int Quality_Min = 0;
public const int Quality_Default = 11;
public const int Quality_Default = 6;
public const int Quality_Max = 11;
public const int MaxInputSize = int.MaxValue - 515; // 515 is the max compressed extra bytes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public BrotliStream(Stream stream, CompressionLevel compressionLevel) : this(str
/// <param name="leaveOpen"><see langword="true" /> to leave the stream open after disposing the <see cref="System.IO.Compression.BrotliStream" /> object; otherwise, <see langword="false" />.</param>
public BrotliStream(Stream stream, CompressionLevel compressionLevel, bool leaveOpen) : this(stream, CompressionMode.Compress, leaveOpen)
{
if ((int)compressionLevel is < BrotliUtils.Quality_Min or > BrotliUtils.Quality_Max)
{
throw new ArgumentException(SR.ArgumentOutOfRange_Enum, nameof(compressionLevel));
}

_encoder.SetQuality(BrotliUtils.GetQualityFromCompressionLevel(compressionLevel));
}

Expand Down

0 comments on commit a09b915

Please sign in to comment.