google / google/brotli

Return of BrotliInputStream.Read(...) Does not work with CopyTo

Open
#899 3 comments 1 reaction 0 assignees View on GitHub
release-v1.1.1
Dominant language
TypeScript
Stars
14.9k
Forks
1.4k
Avg merge
4d 20h
Merged PRs (30d)
9

Description

Not sure what/if there is an intended target, but at least for my case, the csharp code fails when performing a `BrotliInputStream.CopyTo`.

The reason I have identified has to do with this [line](https://github.com/google/brotli/blob/2a51a85aa86abb4c294c65fab57f3d9c69f10080/csharp/org/brotli/dec/BrotliInputStream.cs#L181), which apparently does not conform with a valid output as per the [online docs](https://docs.microsoft.com/en-us/dotnet/api/system.io.stream.read?view=net-5.0#System_IO_Stream_Read_System_Byte___System_Int32_System_Int32_).

Looking further into it, this is necessarily the case, as CopyTo will use a given buffer to continue reading input and eventually copying to destination stream, expecting a 0 when there is nothing written to the buffer ([source code](https://referencesource.microsoft.com/#mscorlib/system/io/stream.cs,218)).

Given that the current code does not confirm with this, can we change the `-1` to `0`?
Fwiw I'd argue this is a safe change; there shouldn't be a particular reason any dependent code would treat a no-op differently depending on an offset or start of buffer write.

Contributor guide

Open the contributing guide

Research direction

Start in csharp/org/brotli/dec/BrotliInputStream.cs at the Read(...) implementation around line 181, then compare its return behavior with the .NET Stream.Read documentation and the referenced CopyTo source. Done means BrotliInputStream.CopyTo works correctly and the no-data return value conforms to the documented Stream contract.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.