dlemstra / dlemstra/Magick.NET

NegativeOrZeroImageSize generated on Ubuntu 24.02, Net6 app, Ghostscript 10.03.1 or 10.04.0

Open
#1,787 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
4k
Forks
451
Avg merge
11h 55m
Merged PRs (30d)
3

Description

### Magick.NET version

Magick.NET-Q16-AnyCPU

### Environment (Operating system, version and so on)

Ubuntu 24.04.1 LTS, dotnet version: 6.0.136

### Description

I'm currently running into an issue with Magick.net-q16-anycpu(14.4.0) added as a nuget package to .net6 application run on Ubuntu 24.04 LTS with GhostScript 10.03.1 and 10.04.0

When I run the same code, on Visual Studio on a Windows machine with the same GhostScript version, it runs fine and images are produced as needed.

As a note, I have been running this code on a prior version on Ubuntu 22 and that worked fine. This issue happened after I upgraded the Nuget packages and GhostScript.

Any thoughts on what could be causing this?

Am attaching a sample pdf that's having this issue.

```
Type: ImageMagick.MagickErrorException
Message: The operation returned null but did not raise an exception.
StackTrace: at ImageMagick.NativeInstance.CheckException(IntPtr exception, IntPtr result) in /_/src/Magick.NET/Native/NativeInstance.cs:line 60
at ImageMagick.MagickImage.NativeMagickImage.ReadFile(IMagickSettings`1 settings) in /_/src/Magick.NET/Generated/Magick.NET.SourceGenerator/ImageMagick.SourceGenerator.NativeInteropGenerator/MagickImage.g.cs:line 6074
at ImageMagick.MagickImage.Read(String fileName, IMagickReadSettings`1 readSettings, Boolean ping) in /_/src/Magick.NET/MagickImage.cs:line 7752
at ImageMagick.MagickImage.Read(String fileName, IMagickReadSettings`1 readSettings) in /_/src/Magick.NET/MagickImage.cs:line 4846
at ImageMagick.MagickImage..ctor(String fileName, IMagickReadSettings`1 readSettings) in /_/src/Magick.NET/MagickImage.cs:line 222

Type: ImageMagick.MagickCorruptImageErrorException
Message: NegativeOrZeroImageSize `/media/fsdev/thumbnails/Decrypted/QA1/SR/9E1268C1-A5B8-4F7F-BD89-3F374625E5AC/6bf84dc4-07e7-4000-a416-53fb60d25c60.png' @ error/image.c/CloneImage/815
StackTrace: at ImageMagick.MagickExceptionHelper.Check(IntPtr exception) in /_/src/Magick.NET/Exceptions/MagickExceptionHelper.cs:line 18
at ImageMagick.NativeHelper.CheckException(IntPtr exception) in /_/src/Magick.NET/Native/NativeHelper.cs:line 20
at ImageMagick.MagickImage.NativeMagickImage.WriteFile(IMagickSettings`1 settings) in /_/src/Magick.NET/Generated/Magick.NET.SourceGenerator/ImageMagick.SourceGenerator.NativeInteropGenerator/MagickImage.g.cs:line 6637
at ImageMagick.MagickImage.Write(String fileName) in /_/src/Magick.NET/MagickImage.cs:line 7147
```

Dotnet Info:

```
.NET SDK (reflecting any global.json):
Version: 6.0.136
Commit: d638663530

Runtime Environment:
OS Name: ubuntu
OS Version: 24.04
OS Platform: Linux
RID: ubuntu.24.04-x64
Base Path: /usr/lib/dotnet/sdk/6.0.136/

global.json file:
Not found

Host:
Version: 6.0.36
Architecture: x64
Commit: f1dd57165b

.NET SDKs installed:
6.0.136 [/usr/lib/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.36 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.36 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]

```

### Steps to Reproduce

Here's the code I wrote. Substituted some variables with dummies here but basically the same thing. The error happens at document.Write.

[testfile.pdf](https://github.com/user-attachments/files/18460603/testfile.pdf)

```
int startIndex = 0;
int pageCount = 2;
Parallel.For(startIndex, pageCount, new ParallelOptions { MaxDegreeOfParallelism = 4 }, pageIndex =>
{

MagickReadSettings settings = new MagickReadSettings()
{
FrameIndex = Convert.ToUInt32(pageIndex),
Density = new Density(68),

};

try
{
using (MagickImage document = new MagickImage(filePath, settings))
{

string thumbnailFileName = $"Image{pageIndex}.png"
string outputPath = Path.Combine(outputDirectory, thumbnailFileName);

document.Write(outputPath);

}

}
catch (MagickException ex)
{
Log(ex)
}
});
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.