[PR #896] Rar2 v20,v26 Multimedia (Audio) decoder fix #1323

Open
opened 2026-01-29 22:19:58 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/adamhathcock/sharpcompress/pull/896

State: closed
Merged: Yes


This is a fix for the Audio Decoder in unpack20 (v20/v26). When decoding a rar that uses the old multimedia compression algorithm an error is raised:

Object reference not set to an instance of an object.
   at SharpCompress.Compressors.Rar.UnpackV1.UnpackUtility.makeDecodeTables(Span`1 lenTab, Int32 offset, Decode dec, Int32 size) in /_/SharpCompress/Compressors/Rar/UnpackV1/UnpackUtility.cs:line 197

This is because the MultiDecode[] objects are never instantiated.

private readonly MultDecode[] MD = new MultDecode[4]; (Unpack20.cs:17)

I looked back through the repo hoping to find and old working commit, but they have never been set. I even dug out the original Unrar project (pre SharpCompress) and that was the same.

Initialising them fixed the crash, but the decompression still wasn't correct. After many hours, I decided to compare the code with the C++ implementation used by 7zip and finally tracked it down to 2 bad casts in the Audio Decoder - (byte) when it should actually be (sbyte). Fortunately the rest of the code seemed to work perfectly after that (big relief).

I've not got any small archives that display this behaviour for use with unit tests. Current tests pass and this fix is being tested on many archives.

:-)

Edit: A combination of this fix and possibly Morilli's fix have fixed the remaining 170 ish archives that were failing to read. There's one outlier to investigate, but it may not be a sharpcompress issue :P

**Original Pull Request:** https://github.com/adamhathcock/sharpcompress/pull/896 **State:** closed **Merged:** Yes --- This is a fix for the Audio Decoder in unpack20 (v20/v26). When decoding a rar that uses the old multimedia compression algorithm an error is raised: ``` Object reference not set to an instance of an object. at SharpCompress.Compressors.Rar.UnpackV1.UnpackUtility.makeDecodeTables(Span`1 lenTab, Int32 offset, Decode dec, Int32 size) in /_/SharpCompress/Compressors/Rar/UnpackV1/UnpackUtility.cs:line 197 ``` This is because the MultiDecode[] objects are never instantiated. `private readonly MultDecode[] MD = new MultDecode[4];` (Unpack20.cs:17) I looked back through the repo hoping to find and old working commit, but they have never been set. I even dug out the original Unrar project (pre SharpCompress) and that was the same. Initialising them fixed the crash, but the decompression still wasn't correct. After many hours, I decided to compare the code with the C++ implementation used by 7zip and finally tracked it down to 2 bad casts in the Audio Decoder - (byte) when it should actually be (sbyte). Fortunately the rest of the code seemed to work perfectly after that (big relief). I've not got any small archives that display this behaviour for use with unit tests. Current tests pass and this fix is being tested on many archives. :-) Edit: A combination of this fix and possibly Morilli's fix have fixed the remaining 170 ish archives that were failing to read. There's one outlier to investigate, but it may not be a sharpcompress issue :P
claunia added the pull-request label 2026-01-29 22:19:58 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1323