PDFsharp icon indicating copy to clipboard operation
PDFsharp copied to clipboard

Exception when displaying some JPG with Core build

Open julienrffr opened this issue 1 year ago • 3 comments

In 6.1.0-preview-1 (and in 6.0.0 as well), using Core build,

Take the HelloWorld program of Core build, Add: var imageStream = File.Open(@"C:\Users\xxx\Downloads\MI6LOGO.jpg", FileMode.Open, FileAccess.Read); XImage xImage = XImage.FromStream(imageStream); gfx.DrawImage(xImage, 0, 0, 100, 100); Where MI6LOGO.jpg is one of those attached files: rtelogo maciflogo It will throw an exception 'Unsupported format' because it does not find expected jpg headers in ImageImporterJpeg.cs in method TestJfifHeader: https://github.com/empira/PDFsharp/blob/b28bc3265e0a15302c04b7b91da0d915a591e167/src/foundation/src/PDFsharp/src/PdfSharp/Drawing.Internal/ImageImporterJpeg.cs#L70

The 3 sub-methods used to determine value of the 'header' boolean return false.

Attached files are legit JPG though so maybe those checks are too strict?

julienrffr avatar Jan 31 '24 16:01 julienrffr

Attached files are legit JPG though so maybe those checks are too strict?

We want to be sure they are JPEG images after all. If there are JPEG variations that are not yet recognized, there is no problem to add them.

ThomasHoevel avatar Jan 31 '24 16:01 ThomasHoevel

It seems that both images are APP2 ICC_Profile (header 0xffe2) JPEG pictures. See https://exiftool.org/TagNames/JPEG.html

julienrffr avatar Feb 01 '24 10:02 julienrffr

Fix provided in PR https://github.com/empira/PDFsharp/pull/82

julienrffr avatar Feb 01 '24 13:02 julienrffr

fixed in 6.1.0

julienrffr avatar Jun 07 '24 12:06 julienrffr