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

MagickImage.Read() should raise an exception when specifying an invalid FrameIndex #813

Open
3 tasks done
martinkoch-geniebelt opened this issue Dec 17, 2020 · 9 comments

Comments

@martinkoch-geniebelt
Copy link

First, thanks for maintaining this - it's great!

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am using the latest version of Magick.NET
  • I have searched open and closed issues to ensure it has not already been reported

Description

When trying to read a specific frame past the last frame from e.g. a PDF, a MagicImage is disposed, and

   No pages will be processed (FirstPage > LastPage).

is written on stdout.

Instead, I think an exception should be raised so that this situation can be dealt with in a nicer way than the sample below.

var magickReadSettings = new MagickReadSettings {FrameIndex = 42};
using (MagickImage mi = new MagickImage())
{
    try 
    {
        mi.Read("onePagePdf.pdf", magickReadSettings);
        // after reading, mi is _disposed_ if we have read past end. Try to access a field to 
        // see if this is the case (and if it is, catch the exception)
        var dummy = mi.Width;
    }
    catch (System.ObjectDisposedException)
    {
        Console.WriteLine("read past the last frame.");
    }
}

An additional nice-to-have would be a fast way of determining the number of pages in a PDF without having to load the whole thing :)

System Configuration

ios, linux.

  • Magick.NET version: 7.22.2.2
  • Environment (Operating system, version and so on): seen on mac, dockerized ubuntu
  • Additional information:
@dlemstra
Copy link
Owner

This looks like a "duplicate" of what was requested in #268

@martinkoch-geniebelt
Copy link
Author

Thanks for a fast response!

There are two parts to this, and, yes, I agree that the 'fast pagecount' is a duplicate, as you say.

However, this bug is about the object being disposed when (IMO :) ) it ought to raise an exception instead.

@dlemstra
Copy link
Owner

Can you share the PDF file so I can reproduce it?

@martinkoch-geniebelt
Copy link
Author

In this example, any pdf with fewer than 42 pages will do. For example, this one

@dlemstra
Copy link
Owner

I am unable to reproduce your issue. Is it possible to create a small sample project with a DockerFile that uses ubuntu that demonstrates this issue?

@martinkoch-geniebelt
Copy link
Author

Thanks again!
I am indeed unable to reproduce this on ubuntu and on windows.

On mac catalina 10.15.7, however, I observe this behavior.

@dlemstra
Copy link
Owner

dlemstra commented Jan 7, 2021

Is it possible to reproduce the issue in GitHub actions?

p.s. Getting a fast page count will become available in the next release.

@martinkoch-geniebelt
Copy link
Author

I'll look into creating a GHA to build on mac

@dlemstra
Copy link
Owner

dlemstra commented Jul 3, 2021

We made some changes in the PDF reading, can you give it another try with the latest release @martinkoch-geniebelt? And I would advise you to use the new PdfInfo class to get the page count.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants