BZip2InputStream: multiple crashes from malformed input
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Start in BZip2InputStream with RecvDecodingTables(), GetAndMoveToFrontDecode(), HbCreateDecodeTables(), and SetupBlock(), then run the five supplied malformed inputs to confirm each failure. Trace stream-derived values before array access and add regression coverage showing malformed data raises BZip2Exception or a similar decoder error rather than IndexOutOfRangeException or NullReferenceException.
Written by the indexing model from the issue text.
Description
Describe the bug
Fuzzing SharpZipLib 1.4.2 with AFL++ and SharpFuzz found 5 unique crashes in BZip2InputStream, all triggered by small malformed .bz2 inputs (42–56 bytes). The BZip2 decoder does not validate header/block fields before using them as array indices, leading to IndexOutOfRangeException (4 crash sites) and NullReferenceException (1 crash site).
These are exploitable for denial of service — any application that decompresses user-supplied .bz2 data using SharpZipLib will crash on these inputs.
Crash 1 — IOOB in GetAndMoveToFrontDecode()
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at ICSharpCode.SharpZipLib.BZip2.BZip2InputStream.GetAndMoveToFrontDecode()
at ICSharpCode.SharpZipLib.BZip2.BZip2InputStream.InitBlock()
at ICSharpCode.SharpZipLib.BZip2.BZip2InputStream..ctor(Stream stream)
Crash 2 — IOOB in HbCreateDecodeTables()
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at ICSharpCode.SharpZipLib.BZip2.BZip2InputStream.HbCreateDecodeTables(...)
at ICSharpCode.SharpZipLib.BZip2.BZip2InputStream.RecvDecodingTables()
at ICSharpCode.SharpZipLib.BZip2.BZip2InputStream.GetAndMoveToFrontDecode()
at ICSharpCode.SharpZipLib.BZip2.BZip2InputStream.InitBlock()
at ICSharpCode.SharpZipLib.BZip2.BZip2InputStream..ctor(Stream stream)
Crash 3 — IOOB in SetupBlock()
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at ICSharpCode.SharpZipLib.BZip2.BZip2InputStream.SetupBlock()
Crash 4 — IOOB in RecvDecodingTables()
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at ICSharpCode.SharpZipLib.BZip2.BZip2InputStream.RecvDecodingTables()
at ICSharpCode.SharpZipLib.BZip2.BZip2InputStream.GetAndMoveToFrontDecode()
at ICSharpCode.SharpZipLib.BZip2.BZip2InputStream.InitBlock()
at ICSharpCode.SharpZipLib.BZip2.BZip2InputStream..ctor(Stream stream)
Crash 5 — NullRef in SetupBlock()
System.NullReferenceException: Object reference not set to an instance of an object.
at ICSharpCode.SharpZipLib.BZip2.BZip2InputStream.SetupBlock()
Reproduction Code
No response
Steps to reproduce
- Create a .NET console app and add
SharpZipLib1.4.2 NuGet package - Paste the reproduction code
- Run the app
- Observe 4x
IndexOutOfRangeExceptionand 1xNullReferenceException
using ICSharpCode.SharpZipLib.BZip2;
// Crash 1 — IOOB in GetAndMoveToFrontDecode (56 bytes)
var crash1 = Convert.FromHexString("425a6839314159265359c1c08044a00030cd00c346299717724538e2000001410000100244a00030cd00c3462997177245385090c1c086e2");
// Crash 2 — IOOB in HbCreateDecodeTables (42 bytes)
var crash2 = Convert.FromHexString("425a6839314159265359c1c080e20003e8410000100244a000303200c3462997177245385090c1c080e2");
// Crash 3 — IOOB in SetupBlock (42 bytes)
var crash3 = Convert.FromHexString("425a6839314159265359c1c080e2a90001410000100244a00030cd00c3462997177245384290c1c080e2");
// Crash 4 — IOOB in RecvDecodingTables (42 bytes)
var crash4 = Convert.FromHexString("425a6839314159265359c1c080e2000001410000100244a000bfcd00c346299717724538500010c080e2");
// Crash 5 — NullRef in SetupBlock (42 bytes)
var crash5 = Convert.FromHexString("425a68c6314159265359c1c080e2000001410000100244a00030cd00c3672997177245385090c1c080e2");
foreach (var (name, data) in new[] { ("crash_1", crash1), ("crash_2", crash2), ("crash_3", crash3), ("crash_4", crash4), ("crash_5", crash5) })
{
try
{
using var stream = new MemoryStream(data);
using var bz2 = new BZip2InputStream(stream);
var buffer = new byte[4096];
while (bz2.Read(buffer, 0, buffer.Length) > 0) { }
Console.WriteLine($"{name}: OK (no crash)");
}
catch (Exception ex)
{
Console.WriteLine($"{name}: {ex.GetType().Name} — {ex.Message}");
}
}
Expected behavior
BZip2InputStream should throw BZip2Exception (or similar) for malformed input, not crash with IndexOutOfRangeException or NullReferenceException. The BZip2 decoder should validate stream-derived values before using them as array indices.
Operating System
Linux
Framework Version
No response
Tags
BZip2
Additional context
- Severity: Medium (denial of service)
- Attack vector: Any application using
BZip2InputStreamto decompress untrusted input - Effect: Unhandled exception terminates the process
- Workaround: Wrap
BZip2InputStreamusage in a try/catch forIndexOutOfRangeExceptionandNullReferenceException - Suggested fix: Add bounds checks in
RecvDecodingTables(),GetAndMoveToFrontDecode(),HbCreateDecodeTables(), andSetupBlock()before using stream-derived values as array indices. Malformed values should throwBZip2Exception(consistent with existing error handling in the decoder) - Found via coverage-guided fuzzing with AFL++ and SharpFuzz
- Dominant language
- C#
- Stars
- 3.9k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from icsharpcode/SharpZipLib
-
*no response* bug
Difficulty 1/5 Under an hour Newbie friendliness 78/100
icsharpcode/SharpZipLib#905 · 1 comment ·
-
SetLevel in ZipFile Openenhancement zip
Difficulty 2/5 1-2 days Newbie friendliness 55/100
icsharpcode/SharpZipLib#903 ·
-
*no response* bug
Difficulty 4/5 3-5 days Newbie friendliness 32/100
icsharpcode/SharpZipLib#901 · 1 comment ·
-
*no response* bug
Difficulty 4/5 3-5 days Newbie friendliness 35/100
icsharpcode/SharpZipLib#894 · 1 comment ·
-
*no response* enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
icsharpcode/SharpZipLib#893 ·
All issues in icsharpcode/SharpZipLib
Similar issues
-
[Feat] 조합 영역 구분선 개선 Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
type/automation type/tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
t/bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
ci-failure-cause test-failure
Difficulty 2/5 1-3 hours Newbie friendliness 82/100