Skip to content

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

Description

@joaovsoares

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

Activity

  1. JimBobSquarePants commented on May 11, 2023

    @JimBobSquarePants
    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.

  2. brianpopow commented on May 11, 2023

    @brianpopow
    Collaborator

    @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.

  3. JimBobSquarePants commented on May 11, 2023

    @JimBobSquarePants
    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?

  4. joaovsoares commented on May 11, 2023

    @joaovsoares
    Author

    ...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?

  5. brianpopow commented on May 11, 2023

    @brianpopow
    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?

  6. joaovsoares commented on May 12, 2023

    @joaovsoares
    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.

  7. brianpopow commented on May 12, 2023

    @brianpopow
    Collaborator

    @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.

  8. joaovsoares commented on May 12, 2023

    @joaovsoares
    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.

  9. JimBobSquarePants commented on Jun 23, 2023

    @JimBobSquarePants
    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.

  10. joaovsoares commented on Jun 23, 2023

    @joaovsoares
    Author

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

  11. added a commit that references this issue on Jun 24, 2023
    6c43909
  12. added a commit that references this issue on Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions