Skip to content

StreamReader.Peek() on a DeflateStream returns -1 early #68983

@Austin-Lamb

Description

@Austin-Lamb

Description

I have code that has a DeflateStream and uses a StreamReader on it - this code works fine in .NET Framework, .NET Core 3.1, and .NET 5 - but it breaks in .NET 6.

When trying to Peek() on the stream, internally StreamReader reads a block out that ends up being smaller than it requested, I'm pretty sure this is due to this breaking change. After that happens, it sets a flag called "_isBlocked" and starts returning -1 from Peek() which is not expected.

This seems like a bug in StreamReader?

Reproduction Steps

Construct a StreamReader over a DeflateStream
Read for a while, peeking as you go

Expected behavior

Peek() returns -1 only at the end of the stream, as it did before

Actual behavior

Peek() returns -1 early in the middle of the file.

Regression?

Yes, regressed in .NET 6

Known Workarounds

Can use StreamReader.EndOfStream instead of looking for -1 from Peek(), but this was still a difficult to hunt down bug on upgrading the .NET version of this library.

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions