Skip to content

Overflow Exception in MakeBigTIFF #40

@mmckean

Description

@mmckean

I'm using your library to create very large tiffs from stitched microscopy images. Your code has been working great! I really appreciate this project! I recently ran into a problem that I've been unable to figure out a solution for. When writing the output for one particularly large scan, I'm running into an Overflow Exception in MakeBigTiff.

For this problematic scan, the details are that I'm writing out a 81,920 x 57,344 tiled tiff. (16bit, single channel) I then create a second tiled tiff that's 40,960 x 28672. I open the larger tiff in "a" mode and add the second image as a page by copying one tile at a time. After all of the tiles have been copied, as the tiff objects are disposed, the exception occurs in the MakeBigTiff method. This code has been working fine now with many other smaller files.

I've stepped through the source code for MakeBigTiff a few times, but so far I'm unable to identify exactly what the issue is. I've had a tough time following the intended logic in this method. I see at least a couple of places where values appear to be read into variables that are too small to hold them. I'm unsure though if some of this is intentional.

I made one attempt at creating a unit test that could reproduce the issue. That first attempt didn't trigger the exception, but it did create a tiff file that couldn't be opened. I'm going to try another attempt using the same exact dimensions as the problematic image - I'll update this ticket with that test, if it works.

Here's the exception text:
System.OverflowException occurred
HResult=-2146233066
Message=Arithmetic operation resulted in an overflow.
Source=BitMiracle.LibTiff.NET40
StackTrace:
at BitMiracle.LibTiff.Classic.Tiff.MakeBigTIFF() in C:\Root\GitHub\Repos\libtiff.net\LibTiff\Internal\Tiff_DirWrite.cs:line 490
InnerException:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions