This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed BufferedStream.ReadByteSlow() to correctly set _readPos (#1)
The following code throws an exception, caused by incorrect logic in BufferedStream.ReadByteSlow(): byte[] input = new byte[] { 1, 2 }; using (var reader = new BufferedStream(new MemoryStream(input), 2)) { reader.ReadByte(); reader.ReadByte(); reader.ReadByte(); byte[] mybuffer = new byte[10]; reader.Read(mybuffer, 0, 1); // throws System.ArgumentOutOfRangeException: 'Non-negative number required.' } When the input data is exhausted through a sequence of ReadByte() calls, ReadByteSlow() does not reset _readPos to zero. This causes a break in the contract specified in Read() - because because _readLen - _readPos is negative. Then the block copy fails because the count to copy is negative. Fix is to reset _readPos to zero before returning -1.
- Loading branch information