empira / PDFsharp

PDFsharp and MigraDoc Foundation for .NET 6 and .NET Framework
https://docs.pdfsharp.net/
Other
527 stars 130 forks source link

Exception when displaying some JPG with Core build #80

Closed julienrffr closed 5 months ago

julienrffr commented 9 months ago

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?

ThomasHoevel commented 9 months ago

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.

julienrffr commented 9 months ago

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

julienrffr commented 9 months ago

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

julienrffr commented 5 months ago

fixed in 6.1.0