@ -19,6 +19,11 @@ internal sealed class LzwDecoder : IDisposable
/// </summary>
private const int MaxStackSize = 4 0 9 6 ;
/// <summary>
/// The maximum bits for a lzw code.
/// </summary>
private const int MaximumLzwBits = 1 2 ;
/// <summary>
/// The null code.
/// </summary>
@ -73,12 +78,12 @@ internal sealed class LzwDecoder : IDisposable
// It is possible to specify a larger LZW minimum code size than the palette length in bits
// which may leave a gap in the codes where no colors are assigned.
// http://www.matthewflickinger.com/lab/whatsinagif/lzw_image_data.asp#lzw_compression
if ( minCodeSize < 2 | | clearCode > MaxStackSize )
if ( minCodeSize < 2 | | minCodeSize > MaximumLzwBits | | clearCode > MaxStackSize )
{
// Don't attempt to decode the frame indices.
// Theoretically we could determine a min code size from the length of the provided
// color palette but we won't bother since the image is most likely corrupted.
GifThrowHelper . ThrowInvalidImageContentException ( "Gif Image does not contain a valid LZW minimum code." ) ;
return ;
}
// The resulting index table length.
@ -245,7 +250,7 @@ internal sealed class LzwDecoder : IDisposable
// It is possible to specify a larger LZW minimum code size than the palette length in bits
// which may leave a gap in the codes where no colors are assigned.
// http://www.matthewflickinger.com/lab/whatsinagif/lzw_image_data.asp#lzw_compression
if ( minCodeSize < 2 | | clearCode > MaxStackSize )
if ( minCodeSize < 2 | | minCodeSize > MaximumLzwBits | | clearCode > MaxStackSize )
{
// Don't attempt to decode the frame indices.
// Theoretically we could determine a min code size from the length of the provided