C# library can enter infinite loop on decompression.
- Dominant language
- TypeScript
- Stars
- 14.9k
- Forks
- 1.4k
- Avg merge
- 4d 20h
- Merged PRs (30d)
- 9
Description
Hi,
I happened upon an odd bug when attempting to decompress data which was not a valid brotli stream using the C# library which caused my application to hang. I tracked the bug to this line:
https://github.com/google/brotli/blob/d74b0a4a22163792aec1b91739c1938a66867ae8/csharp/org/brotli/dec/BitReader.cs#L257
The Read method will never return -1, it returns 0 on EoF (I think this is just a translation error from Java, this same issue is noted here: https://github.com/google/brotli/blob/d74b0a4a22163792aec1b91739c1938a66867ae8/csharp/org/brotli/dec/BitReader.cs#L79 but didn't get changed for the other call) - if EoF is hit early in CopyBytes, an infinite loop is entered with the Read method returning 0 over and over and never triggering the exception as it should.
The fix should just be to change -1 to 0 - this correctly triggered the `BrotliRuntimeException` in my code.
Contributor guide
Research direction
Start in csharp/org/brotli/dec/BitReader.cs at the linked line and inspect CopyBytes and the Read method's end-of-file behavior. Change the EOF comparison as described, then verify that invalid Brotli data raises BrotliRuntimeException instead of looping indefinitely.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100