mirror of
https://github.com/google/brotli.git
synced 2026-09-23 07:05:31 +00:00
C# library can enter infinite loop on decompression. #552
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 @AlexC-CCL on GitHub (Sep 30, 2025).
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:
d74b0a4a22/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:
d74b0a4a22/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
BrotliRuntimeExceptionin my code.@eustas commented on GitHub (Oct 21, 2025):
This seems to be fixed in Java code; C# transpiled code needs to be refreshed...
@eustas commented on GitHub (Oct 21, 2025):
Going soon to change transpiler from sharpen to one used for other languages (go/js/ts/kt). In the meanwhile will add .csproj files and build/test CI workflows.