From 6c439092fd5b89dfddd6b67e13be5c869652a0ad Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sat, 24 Jun 2023 16:09:29 +0200 Subject: [PATCH] If we read a extension code, read the next 5 bits because some encoder write premature EOL codes instead of extension codes. Throw NotSupportedException, if its actually a Extension code. Fixes #2451 --- .../Compression/Decompressors/T6BitReader.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/T6BitReader.cs b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/T6BitReader.cs index 8be0939d3..fe71b204b 100644 --- a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/T6BitReader.cs +++ b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/T6BitReader.cs @@ -125,13 +125,29 @@ internal sealed class T6BitReader : T4BitReader if (value == Len7Code0000000.Code) { this.Code = Len7Code0000000; - return false; + + // We do not support Extensions1D codes, but some encoders (scanner from epson) write a premature EOL code, + // which at this point cannot be distinguished from a distinguish, because we read the data bit by bit. + // Read the next 5 bit, if its a EOL code return true, indicating its the end of the image. + if (this.ReadValue(5) == 1) + { + return true; + } + + throw new NotSupportedException("ccitt extensions 1D codes are not supported."); } if (value == Len7Code0000001.Code) { this.Code = Len7Code0000001; - return false; + + // Same as above, we do not support Extensions2D codes, but it could be a EOL instead. + if (this.ReadValue(5) == 1) + { + return true; + } + + throw new NotSupportedException("ccitt extensions 2D codes are not supported."); } if (value == Len7Code0000011.Code)