Repository navigation
Huge images cause negative allocation size error #2959
Description
Activity
What dimensions is your image?
w: 97,943
h: 51,536That comes out to 5,047,590,448 pixels which is larger than an
uintcan hold, so perhapslongshould be used?It's a huge image, but my machine has enough memory to load it, so it should load. I think there is a bug with large image dimensions overflowing and becoming negative.
If I recall correctly, this runs into a limitation with
ArrayPool<T>in that the maximum number of elements that can be rented is anint, while every pixel is RGBA, so four bytes. It's likely more of an issue with the allocation strategy, as was the case in the chunk decoder previously.Reacted by James Jackson-SouthThat’s exactly the issue. The code requires refactoring in the decoder to work per-row. I have a fix in mind already.
I'm looking to process some large images this winter and was wondering if any progress has been made on this issue and if there's a rough estimate of a completion date?
This is a deceptively tricky issue.
While I can patch a workaround in v3 by checking for
NoneTiffCompression, properly handling this in v4 requires a more comprehensive solution. The core problem is that there's no reliable way to know how many compressed bytes correspond to a single uncompressed row without maintaining decompression state or implementing more granular stream control. Because of that, it's difficult to estimate a completion date until I’ve explored and tested a robust design.Thanks for the update, I appreciate it.
I haven't looked at the code myself, but perhaps allow a user-specified option for max row size? Try to decompress in a
try/catchblock in a loop and steadily increase the buffer until either an exception is not thrown, or the user-specified limit is hit? Just a thought.- added 2 commits that reference this issue
on Oct 24, 2025 I've confirmed this works with the huge Vera Rubin Telescope image sample I provided above. Thank you for fixing this and I'm looking forward to seeing it published on nuget. 👍
Reacted by James Jackson-SouthThanks for testing @mfeemster
I should be able to do a release in the next day or two.
Reacted by Tieson TrowbridgeReleased!
Reacted by Matt FeemsterI've tried rebuilding and running my project with the updated package and it still fails. Did the changes somehow not make it to the 3.1.12 release binary?
If I build ImageSharp from source and put these lines in
ImageSharp.Tests.ProfilingSandbox.Program.cs, it works fine:var filename = @"C:\Temp\Vera Rubin Cosmic Treasure Chest Im1.tif"; var image = SixLabors.ImageSharp.Image.Load<Rgba32>(filename);However, the same lines in my project which uses the ImageSharp 3.1.12 dll via nuget package will fail. Both attempts target x64.
The changelog is here.
https://github.com/SixLabors/ImageSharp/releases/tag/v3.1.12
This is automatically generated from commits.
Update
Just tested using LINQpad, definitely working.

Disregard my comment. It was a very strange scenario where I was running on another machine with an older version of Powershell installed which was parsing my command line arguments incorrectly. Once I used the new Powershell, it worked fine. We're good now!
Reacted by James Jackson-South
Prerequisites
DEBUGandRELEASEmodeImageSharp version
Latest as of 6/25/2025
Other ImageSharp packages and versions
None
Environment (Operating system, version and so on)
Windows 10
.NET Framework version
.NET 9
Description
I am trying to decode this extremely large 14GB TIF file: https://rubinobservatory.org/gallery/collections/first-look-gallery/mlis3sriah6pn6nfr5ecp46h3i
and get an error: "Failed to allocate buffers for possibly degenerate dimensions: 0x0."
My machine has 64GB RAM and I set the buffer sizes to 40,000 (40GB) and it still happens.
From the stack trace below, it appears that when an image gets sufficiently large, the buffer sizes overflow and wrap to negative, thus throwing an exception. Possibly related to:
#2874
and also noted in:
#2870
It threw an exception with this stack trace:
Steps to Reproduce
Download the file linked in the description.
Run the code in the description on a machine with sufficient RAM.
See the exception get thrown.
Images
No response