Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle EOF in Jpeg bit reader when data is bad to prevent DOS attack. #2516

Merged
merged 9 commits into from
Aug 30, 2023
Prev Previous commit
Next Next commit
Stream seek can exceed the length of a stream
  • Loading branch information
JimBobSquarePants committed Aug 23, 2023
commit 62aaa4df64c46b5f35ff4e18229d70aa49afcb92
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public bool FindNextMarker()
private int ReadStream()
{
int value = this.badData ? 0 : this.stream.ReadByte();
if (value == -1 || this.stream.Position == this.stream.Length)
if (value == -1 || this.stream.Position >= this.stream.Length)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeking to any location beyond the length of the stream is supported.

https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.position?view=net-7.0#remarks

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out the fix is bad. It's somehow preventing complete data reading.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proper fix implemented now.

{
// We've encountered the end of the file stream which means there's no EOI marker
// in the image or the SOS marker has the wrong dimensions set.
Expand Down