@@ -34,7 +34,12 @@ public static IImageFormat DetectFormat(ReadOnlySpan<byte> buffer)
3434 /// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
3535 public static unsafe IImageFormat DetectFormat ( DecoderOptions options , ReadOnlySpan < byte > buffer )
3636 {
37- Guard . NotNull ( options , nameof ( options . Configuration ) ) ;
37+ Guard . NotNull ( options , nameof ( options ) ) ;
38+
39+ if ( buffer . IsEmpty )
40+ {
41+ throw new UnknownImageFormatException ( "Cannot detect image format from empty data." ) ;
42+ }
3843
3944 fixed ( byte * ptr = buffer )
4045 {
@@ -66,6 +71,13 @@ public static ImageInfo Identify(ReadOnlySpan<byte> buffer)
6671 /// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
6772 public static unsafe ImageInfo Identify ( DecoderOptions options , ReadOnlySpan < byte > buffer )
6873 {
74+ Guard . NotNull ( options , nameof ( options ) ) ;
75+
76+ if ( buffer . IsEmpty )
77+ {
78+ throw new UnknownImageFormatException ( "Cannot identify image format from empty data." ) ;
79+ }
80+
6981 fixed ( byte * ptr = buffer )
7082 {
7183 using UnmanagedMemoryStream stream = new ( ptr , buffer . Length ) ;
@@ -99,6 +111,13 @@ public static Image Load(ReadOnlySpan<byte> buffer)
99111 /// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
100112 public static unsafe Image Load ( DecoderOptions options , ReadOnlySpan < byte > buffer )
101113 {
114+ Guard . NotNull ( options , nameof ( options ) ) ;
115+
116+ if ( buffer . IsEmpty )
117+ {
118+ throw new UnknownImageFormatException ( "Cannot load image from empty data." ) ;
119+ }
120+
102121 fixed ( byte * ptr = buffer )
103122 {
104123 using UnmanagedMemoryStream stream = new ( ptr , buffer . Length ) ;
@@ -133,6 +152,13 @@ public static Image<TPixel> Load<TPixel>(ReadOnlySpan<byte> data)
133152 public static unsafe Image < TPixel > Load < TPixel > ( DecoderOptions options , ReadOnlySpan < byte > data )
134153 where TPixel : unmanaged, IPixel < TPixel >
135154 {
155+ Guard . NotNull ( options , nameof ( options ) ) ;
156+
157+ if ( data . IsEmpty )
158+ {
159+ throw new UnknownImageFormatException ( "Cannot load image from empty data." ) ;
160+ }
161+
136162 fixed ( byte * ptr = data )
137163 {
138164 using UnmanagedMemoryStream stream = new ( ptr , data . Length ) ;
0 commit comments