From 0e13ae589c62b82e0dfb37c831c25cb1be2dc66a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Kanda?= Date: Thu, 25 Sep 2025 16:25:00 +0200 Subject: [PATCH] XImage.FromFile/FromStream throws InvalidOperationException (Unsupported image format.) for valid JPGs #309 --- .../src/PdfSharp/Drawing.Internal/ImageImporterJpeg.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/foundation/src/PDFsharp/src/PdfSharp/Drawing.Internal/ImageImporterJpeg.cs b/src/foundation/src/PDFsharp/src/PdfSharp/Drawing.Internal/ImageImporterJpeg.cs index 76330bac..c06f8583 100644 --- a/src/foundation/src/PDFsharp/src/PdfSharp/Drawing.Internal/ImageImporterJpeg.cs +++ b/src/foundation/src/PDFsharp/src/PdfSharp/Drawing.Internal/ImageImporterJpeg.cs @@ -304,7 +304,8 @@ bool MoveToNextHeader(StreamReaderHelper stream) return false; // Check for standalone markers. - if (headerType == 0x01 || headerType >= 0xd0 && headerType <= 0xd7) + // Also check for zero-byte stuff in entropy-coded data segments. + if (headerType == 0x00 || headerType == 0x01 || headerType >= 0xd0 && headerType <= 0xd7) { stream.CurrentOffset += 2; return true;