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

Reading from StreamDecorator with oversized buffer fails #88

Closed
aunverdorben-dap opened this issue May 25, 2022 · 0 comments
Closed

Reading from StreamDecorator with oversized buffer fails #88

aunverdorben-dap opened this issue May 25, 2022 · 0 comments

Comments

@aunverdorben-dap
Copy link
Contributor

aunverdorben-dap commented May 25, 2022

Assume you have a CFStream with a length of 670 bytes. When accessing the data from the CFStream via StreamDecorator and reading from it into an oversized buffer like so

Stream readStream = cf.RootStorage.GetStream("ANewStream").AsIOStream()
var buffer = new byte[81920];
var readBytes = readStream.Read(buffer, 0, buffer.Length)

a System.ArgumentOutOfRangeException will occur.

Now, one could argue the buffer size should not exceed the length of the stream but when using .NET funcionality like Stream.CopyTo or wrapping a CompressedStream around the StreamDecorator the exception will also occur, because Stream.CopyTo and DeflateStream both work with their default buffer sizes a) for performance/IO throughput reasons and b) because they need to be able to work with non-seekable streams and even with streams with unknown length.

The Stream.Read documentation states:

Returns
Int32
The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.

So it's perfectly ok to request 81920 (see example code above) but only get 670 bytes of data when there's simply not more data available.

aunverdorben-dap added a commit to DAP-GmbH/openmcdf that referenced this issue May 25, 2022
aunverdorben-dap added a commit to DAP-GmbH/openmcdf that referenced this issue May 25, 2022
aunverdorben-dap added a commit to DAP-GmbH/openmcdf that referenced this issue Aug 30, 2022
aunverdorben-dap added a commit to DAP-GmbH/openmcdf that referenced this issue Aug 30, 2022
ironfede added a commit that referenced this issue Aug 30, 2022
Added unit test method to demonstrate issue #88 and provided a fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant