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

"System.NotSupportedException: ccitt extensions are not supported" when loading some tifs #2451

Closed
4 tasks done
joaovsoares opened this issue May 9, 2023 · 10 comments
Closed
4 tasks done

Comments

@joaovsoares
Copy link

joaovsoares commented May 9, 2023

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

ImageSharp version

3.0.2-alpha.0.14

Other ImageSharp packages and versions

No

Environment (Operating system, version and so on)

Linux

.NET Framework version

NET 6

Description

When loading some Tiffs, we received this exception while decoding.
Other windows applications can open the file.

BTW: I have bought a Commercial License (couldnt find the checkbox to inform).

System.NotSupportedException: ccitt extensions are not supported.
   at SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors.T6TiffCompression.Decode2DScanline(T6BitReader bitReader, Boolean whiteIsZero, CcittReferenceScanline referenceScanline, Span`1 scanline)
   at SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors.T6TiffCompression.Decompress(BufferedReadStream stream, Int32 byteCount, Int32 stripHeight, Span`1 buffer, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.Tiff.TiffDecoderCore.DecodeStripsChunky[TPixel](ImageFrame`1 frame, Int32 rowsPerStrip, Span`1 stripOffsets, Span`1 stripByteCounts, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.Tiff.TiffDecoderCore.DecodeImageWithStrips[TPixel](ExifProfile tags, ImageFrame`1 frame, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.Tiff.TiffDecoderCore.DecodeFrame[TPixel](ExifProfile tags, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.Tiff.TiffDecoderCore.Decode[TPixel](BufferedReadStream stream, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.ImageDecoderUtilities.Decode[TPixel](IImageDecoderInternals decoder, Configuration configuration, Stream stream, Func`3 largeImageExceptionFactory, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.Tiff.TiffDecoder.Decode[TPixel](DecoderOptions options, Stream stream, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.Tiff.TiffDecoder.Decode(DecoderOptions options, Stream stream, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.ImageDecoder.<>c__DisplayClass1_0.<Decode>b__0(Stream s)
   at SixLabors.ImageSharp.Formats.ImageDecoder.WithSeekableStream[T](DecoderOptions options, Stream stream, Func`2 action)
   at SixLabors.ImageSharp.Formats.ImageDecoder.Decode(DecoderOptions options, Stream stream)

Steps to Reproduce

Load the provided images from a stream.
The error throws when decoding.

public static MemoryStream ConverterPara(MemoryStream imagemStream)
{
    var pngEncoder = new PngEncoder()
    {
        FilterMethod = PngFilterMethod.Adaptive,
        CompressionLevel = PngCompressionLevel.BestCompression,
        TransparentColorMode = PngTransparentColorMode.Clear,
        ColorType = PngColorType.Grayscale,
        BitDepth = PngBitDepth.Bit4,
        SkipMetadata = true
    };

    imagemStream.Position = 0;
    var resultadoStream = new MemoryStream();

    using (var imagem = Image.Load(imagemStream))
    {
        using (var clone = imagem.CloneAs<L8>())
            clone.Save(resultadoStream, pngEncoder);
    }

    return resultadoStream;
}

Images

@JimBobSquarePants
Copy link
Member

Thanks for the files and details. I'll have a look at how libtiff handles these compression types asap. Hopefully an easy port.

Re the commercial license. As of v3 there's no support guarantees with the commercial license.

@brianpopow
Copy link
Collaborator

brianpopow commented May 11, 2023

@JimBobSquarePants The provided image Epson_1411_1 uses CCITT Group 4 compression. The last row (2198) does not contain enough data. It seems it has a premature end of line code. I think we can treat all pixels as white if that's happening.

The problem is the it is that the EOL code (12 bits first 11 all 0 with the last one being 1) is ambiguous with the Extensions1D code (7 bits with all zero's).
Since we are reading the data bit by bit, we read the EOL code as being Extensions1D.

Not sure yet how we can detect its meant to be EOL.

@JimBobSquarePants
Copy link
Member

@brianpopow Thanks for the information. I hadn't started digging yet.

Yeah that seems like a bit of a puzzle. It might be worth seeing how other libraries handle it. Maybe libtiff.NET would be easy to compare?

@joaovsoares
Copy link
Author

joaovsoares commented May 11, 2023

...I'll have a look at how libtiff handles these compression types asap. Hopefully an easy port.

Thanks in advance.

Re the commercial license. As of v3 there's no support guarantees with the commercial license.

I don't know if I understood correctly. But then how should we proceed to have guaranteed support even with v3? Should we update our license somehow?

@brianpopow
Copy link
Collaborator

Yeah that seems like a bit of a puzzle. It might be worth seeing how other libraries handle it. Maybe libtiff.NET would be easy to compare?

@JimBobSquarePants I would suggest the following: If we encounter a Extensions1D code, we read the next 5 bits and if it turns out to be a EOL and not a Extensions1D, we return that. Otherwise throw a NotSupported Exception for the Extension1D code.
I can provide a fix, if this sounds like a valid plan.

@joaovsoares can we use the provided images for unit tests?

@joaovsoares
Copy link
Author

@joaovsoares can we use the provided images for unit tests?

Unfortunately, in this case you cannot use these images for unit tests.
By the way, can I delete them from the first post? I assume you already downloaded it.

@brianpopow
Copy link
Collaborator

brianpopow commented May 12, 2023

@joaovsoares can we use the provided images for unit tests?

Unfortunately, in this case you cannot use these images for unit tests. By the way, can I delete them from the first post? I assume you already downloaded it.

@joaovsoares yes you can delete them, I have downloaded them. Would you be able to provide other images with the same issue, which I could use? It will be hard to recreate those issue, because I think they are not following the spec correctly.

@joaovsoares
Copy link
Author

@joaovsoares yes you can delete them, I have downloaded them. Would you be able to provide other images with the same issue, which I could use? It will be hard to recreate those issue, because I think they are not following the spec correctly.

I will try. I just requested sample images that can be used publicly.

@JimBobSquarePants
Copy link
Member

Let's push on with the fix using the original images to test locally. We can add a note to the code if we cannot recreate the issues in a new file.

@joaovsoares
Copy link
Author

Thanks, guys.
BTW: now @yuridiniz will follow up on the subject here with you, in my place.

JimBobSquarePants added a commit that referenced this issue Jun 25, 2023
Tiff: ccitt compression, fix for issue #2451
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants