Skip to content

Commit 5d82124

Browse files
authored
Merge pull request #1742 from SixLabors/bp/unsupportedjpegs
Throw NotSupportedException for arithmetic coding and lossless jpeg's
2 parents 36f4ad4 + d1fe136 commit 5d82124

File tree

11 files changed

+180
-32
lines changed

11 files changed

+180
-32
lines changed

src/ImageSharp/Formats/Jpeg/JpegConstants.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ internal static class Markers
133133
/// </summary>
134134
public const byte APP15 = 0xEF;
135135

136+
/// <summary>
137+
/// Define arithmetic coding conditioning marker.
138+
/// </summary>
139+
public const byte DAC = 0xCC;
140+
136141
/// <summary>
137142
/// The text comment marker
138143
/// </summary>
@@ -173,6 +178,56 @@ internal static class Markers
173178
/// </summary>
174179
public const byte SOF2 = 0xC2;
175180

181+
/// <summary>
182+
/// Start of Frame marker, non differential lossless, Huffman coding.
183+
/// </summary>
184+
public const byte SOF3 = 0xC3;
185+
186+
/// <summary>
187+
/// Start of Frame marker, differential, Huffman coding, Differential sequential DCT.
188+
/// </summary>
189+
public const byte SOF5 = 0xC5;
190+
191+
/// <summary>
192+
/// Start of Frame marker, differential, Huffman coding, Differential progressive DCT.
193+
/// </summary>
194+
public const byte SOF6 = 0xC6;
195+
196+
/// <summary>
197+
/// Start of Frame marker, differential lossless, Huffman coding.
198+
/// </summary>
199+
public const byte SOF7 = 0xC7;
200+
201+
/// <summary>
202+
/// Start of Frame marker, non-differential, arithmetic coding, Extended sequential DCT.
203+
/// </summary>
204+
public const byte SOF9 = 0xC9;
205+
206+
/// <summary>
207+
/// Start of Frame marker, non-differential, arithmetic coding, Progressive DCT.
208+
/// </summary>
209+
public const byte SOF10 = 0xCA;
210+
211+
/// <summary>
212+
/// Start of Frame marker, non-differential, arithmetic coding, Lossless (sequential).
213+
/// </summary>
214+
public const byte SOF11 = 0xCB;
215+
216+
/// <summary>
217+
/// Start of Frame marker, differential, arithmetic coding, Differential sequential DCT.
218+
/// </summary>
219+
public const byte SOF13 = 0xCD;
220+
221+
/// <summary>
222+
/// Start of Frame marker, differential, arithmetic coding, Differential progressive DCT.
223+
/// </summary>
224+
public const byte SOF14 = 0xCE;
225+
226+
/// <summary>
227+
/// Start of Frame marker, differential, arithmetic coding, Differential lossless (sequential).
228+
/// </summary>
229+
public const byte SOF15 = 0xCF;
230+
176231
/// <summary>
177232
/// Define Huffman Table(s)
178233
/// <remarks>

src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,28 @@ internal void ParseStream(BufferedReadStream stream, HuffmanScanDecoder scanDeco
247247
this.ProcessStartOfFrameMarker(stream, remaining, fileMarker, metadataOnly);
248248
break;
249249

250+
case JpegConstants.Markers.SOF5:
251+
JpegThrowHelper.ThrowNotSupportedException("Decoding jpeg files with differential sequential DCT is not supported.");
252+
break;
253+
254+
case JpegConstants.Markers.SOF6:
255+
JpegThrowHelper.ThrowNotSupportedException("Decoding jpeg files with differential progressive DCT is not supported.");
256+
break;
257+
258+
case JpegConstants.Markers.SOF3:
259+
case JpegConstants.Markers.SOF7:
260+
JpegThrowHelper.ThrowNotSupportedException("Decoding lossless jpeg files is not supported.");
261+
break;
262+
263+
case JpegConstants.Markers.SOF9:
264+
case JpegConstants.Markers.SOF10:
265+
case JpegConstants.Markers.SOF11:
266+
case JpegConstants.Markers.SOF13:
267+
case JpegConstants.Markers.SOF14:
268+
case JpegConstants.Markers.SOF15:
269+
JpegThrowHelper.ThrowNotSupportedException("Decoding jpeg files with arithmetic coding is not supported.");
270+
break;
271+
250272
case JpegConstants.Markers.SOS:
251273
if (!metadataOnly)
252274
{
@@ -326,6 +348,10 @@ internal void ParseStream(BufferedReadStream stream, HuffmanScanDecoder scanDeco
326348
case JpegConstants.Markers.COM:
327349
stream.Skip(remaining);
328350
break;
351+
352+
case JpegConstants.Markers.DAC:
353+
JpegThrowHelper.ThrowNotSupportedException("Decoding jpeg files with arithmetic coding is not supported.");
354+
break;
329355
}
330356
}
331357

src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
88
{
99
internal static class JpegThrowHelper
1010
{
11+
/// <summary>
12+
/// Cold path optimization for throwing <see cref="NotSupportedException"/>'s.
13+
/// </summary>
14+
/// <param name="errorMessage">The error message for the exception.</param>
15+
[MethodImpl(InliningOptions.ColdPath)]
16+
public static void ThrowNotSupportedException(string errorMessage) => throw new NotSupportedException(errorMessage);
17+
1118
/// <summary>
1219
/// Cold path optimization for throwing <see cref="InvalidImageContentException"/>'s.
1320
/// </summary>

0 commit comments

Comments
 (0)