You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Image.Identify throws ArgumentOutOfRangeException on empty unseekable stream #1903
I have verified that I am running the latest version of ImageSharp
I have verified if the problem exist in both DEBUG and RELEASE mode
I have searched open and closed issues to ensure it has not already been reported
Description
Image.Identify throws ArgumentOutOfRangeException when provided an empty unseekable stream.
Stack trace:
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: value
at SixLabors.ImageSharp.IO.ChunkedMemoryStream.ThrowArgumentOutOfRange(String value)
at SixLabors.ImageSharp.IO.ChunkedMemoryStream.set_Position(Int64 value)
at SixLabors.ImageSharp.Image.WithSeekableStream[T](Configuration configuration, Stream stream, Func`2 action)
at SixLabors.ImageSharp.Image.Identify(Configuration configuration, Stream stream, IImageFormat& format)
at SixLabors.ImageSharp.Image.Identify(Stream stream)
Rather than throwing an exception for this case, I'd expect ChunkedMemoryStream to support seeking to positions at and beyond the end of the stream. Then you get the same behavior for empty (and also non-empty) seekable and unseekable streams (ex. Image.Identify would return null in this case).
Activity
JimBobSquarePants commentedon Dec 21, 2021
Thanks for your detailed report! Really useful.
We'll check for zero length early and throw a
NotSupportedException.carlreinke commentedon Dec 21, 2021
Rather than throwing an exception for this case, I'd expect
ChunkedMemoryStreamto support seeking to positions at and beyond the end of the stream. Then you get the same behavior for empty (and also non-empty) seekable and unseekable streams (ex.Image.Identifywould returnnullin this case).See the Remarks for Stream.Position:
Don't throw when Position is out of range. Fix #1903
JimBobSquarePants commentedon Dec 21, 2021
@carlreinke Yep, you're correct. Docs are explicit in this regard. I've opened #1907 to fix this.