mirror of
https://github.com/google/brotli.git
synced 2026-09-22 06:35:52 +00:00
Return of BrotliInputStream.Read(...) Does not work with CopyTo #384
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @solamanhuq on GitHub (Apr 27, 2021).
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, which apparently does not conform with a valid output as per the online docs.
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).
Given that the current code does not confirm with this, can we change the
-1to0?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.
@paulushub commented on GitHub (Sep 14, 2021):
Just came here to report the same issue. Since the C# version is a translation of the Java version, someone thought Java return value of
-1will work for C#/.NET.Fixed it in my local copy.
@eustas commented on GitHub (Dec 15, 2021):
Hello. Thanks for the heads-up.
I have plans for refreshing the C# code (and code-generation). Will include this fix in the update.
@TheRealNem commented on GitHub (Sep 19, 2022):
This bit me too. Some .Net API code checks explicitly for 0, so things crash in confusing ways when you pass in a BrotliInputStream (in my case it was a XmlReader). If you change the return value, be aware that BrotliInputStream.ReadByte also compares the return value of BrotliInputStream.Read to -1.