Skip to content

Commit

Permalink
Merge pull request #2835 from stefannikolei/sn/internaldetectformat
Browse files Browse the repository at this point in the history
#2807 Add early return in InternalDetectFormat
  • Loading branch information
JimBobSquarePants authored Nov 6, 2024
2 parents 21ec18e + a8ea3e0 commit 702d71f
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/ImageSharp/Image.Decode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,18 @@ private static IImageFormat InternalDetectFormat(
// Does the given stream contain enough data to fit in the header for the format
// and does that data match the format specification?
// Individual formats should still check since they are public.
IImageFormat? format = null;
foreach (IImageFormatDetector formatDetector in configuration.ImageFormatsManager.FormatDetectors)
{
if (formatDetector.HeaderSize <= headersBuffer.Length && formatDetector.TryDetectFormat(headersBuffer, out IImageFormat? attemptFormat))
{
format = attemptFormat;
return attemptFormat;
}
}

if (format is null)
{
ImageFormatManager.ThrowInvalidDecoder(configuration.ImageFormatsManager);
}
ImageFormatManager.ThrowInvalidDecoder(configuration.ImageFormatsManager);

return format;
// Need to write this otherwise compiler is not happy
return null;
}

/// <summary>
Expand Down

0 comments on commit 702d71f

Please sign in to comment.