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

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

📋 Pull Request Information

Original PR: https://github.com/adamhathcock/sharpcompress/pull/896
Author: @Nanook
Created: 2/11/2025
Status: Merged
Merged: 2/12/2025
Merged by: @adamhathcock

Base: masterHead: rar_unpack20_audio_fix


📝 Commits (2)

  • c41888b Rar2 v20,v26 Multimedia (Audio) decoder fix
  • 6bc690b Seriously?

📊 Changes

1 file changed (+34 additions, -4 deletions)

View changed files

📝 src/SharpCompress/Compressors/Rar/UnpackV1/Unpack20.cs (+34 -4)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/adamhathcock/sharpcompress/pull/896 **Author:** [@Nanook](https://github.com/Nanook) **Created:** 2/11/2025 **Status:** ✅ Merged **Merged:** 2/12/2025 **Merged by:** [@adamhathcock](https://github.com/adamhathcock) **Base:** `master` ← **Head:** `rar_unpack20_audio_fix` --- ### 📝 Commits (2) - [`c41888b`](https://github.com/adamhathcock/sharpcompress/commit/c41888b3386b9d5694a07cd69063526722e24991) Rar2 v20,v26 Multimedia (Audio) decoder fix - [`6bc690b`](https://github.com/adamhathcock/sharpcompress/commit/6bc690b50b9b2e684075991d17f2a55924e548d1) Seriously? ### 📊 Changes **1 file changed** (+34 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `src/SharpCompress/Compressors/Rar/UnpackV1/Unpack20.cs` (+34 -4) </details> ### 📄 Description 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 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 22:19:57 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1318