[PR #638] [MERGED] Rar2 fix with new unit tests that fail on previous build. #1135

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

📋 Pull Request Information

Original PR: https://github.com/adamhathcock/sharpcompress/pull/638
Author: @Nanook
Created: 2/15/2022
Status: Merged
Merged: 2/16/2022
Merged by: @adamhathcock

Base: masterHead: rar2MultiWithTest


📝 Commits (1)

  • dab157b Rar2 fix with new unit tests that fail on previous build.

📊 Changes

10 files changed (+26 additions, -1 deletions)

View changed files

📝 src/SharpCompress/Common/Rar/RarEntry.cs (+1 -1)
📝 tests/SharpCompress.Test/Rar/RarArchiveTests.cs (+25 -0)
tests/TestArchives/Archives/Rar2.multi.r00 (+0 -0)
tests/TestArchives/Archives/Rar2.multi.r01 (+0 -0)
tests/TestArchives/Archives/Rar2.multi.r02 (+0 -0)
tests/TestArchives/Archives/Rar2.multi.r03 (+0 -0)
tests/TestArchives/Archives/Rar2.multi.r04 (+0 -0)
tests/TestArchives/Archives/Rar2.multi.r05 (+0 -0)
tests/TestArchives/Archives/Rar2.multi.rar (+0 -0)
tests/TestArchives/Archives/Rar2.rar (+0 -0)

📄 Description

I noticed files within WinRar2.8 archives were not decompressing properly. Some were fine, others were fine at the start then corrupt half way through the file. I was able to reproduce this behaviour by using WinRar2.8 to create SharpCompress test archives.

After debugging the streams to confirm the RAR compressed parts were being extracted correctly, I noticed it was the decoding that was failing. I stumbled upon RarEntry.IsRarV3 property and added FileHeader.CompressionAlgorithm == 20 || FileHeader.CompressionAlgorithm == 26 to the logic. This forces it to use the UnpackV1 code rather than UnpackV2017. This fixes it.

This PR also includes the UnitTests and Archives. Hopefully it will be useful

I think it fixes this issue also: https://github.com/adamhathcock/sharpcompress/issues/619

Thanks.


🔄 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/638 **Author:** [@Nanook](https://github.com/Nanook) **Created:** 2/15/2022 **Status:** ✅ Merged **Merged:** 2/16/2022 **Merged by:** [@adamhathcock](https://github.com/adamhathcock) **Base:** `master` ← **Head:** `rar2MultiWithTest` --- ### 📝 Commits (1) - [`dab157b`](https://github.com/adamhathcock/sharpcompress/commit/dab157bb71d4a49c024231f588058f2bf0abce46) Rar2 fix with new unit tests that fail on previous build. ### 📊 Changes **10 files changed** (+26 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/SharpCompress/Common/Rar/RarEntry.cs` (+1 -1) 📝 `tests/SharpCompress.Test/Rar/RarArchiveTests.cs` (+25 -0) ➕ `tests/TestArchives/Archives/Rar2.multi.r00` (+0 -0) ➕ `tests/TestArchives/Archives/Rar2.multi.r01` (+0 -0) ➕ `tests/TestArchives/Archives/Rar2.multi.r02` (+0 -0) ➕ `tests/TestArchives/Archives/Rar2.multi.r03` (+0 -0) ➕ `tests/TestArchives/Archives/Rar2.multi.r04` (+0 -0) ➕ `tests/TestArchives/Archives/Rar2.multi.r05` (+0 -0) ➕ `tests/TestArchives/Archives/Rar2.multi.rar` (+0 -0) ➕ `tests/TestArchives/Archives/Rar2.rar` (+0 -0) </details> ### 📄 Description I noticed files within WinRar2.8 archives were not decompressing properly. Some were fine, others were fine at the start then corrupt half way through the file. I was able to reproduce this behaviour by using WinRar2.8 to create SharpCompress test archives. After debugging the streams to confirm the RAR compressed parts were being extracted correctly, I noticed it was the decoding that was failing. I stumbled upon `RarEntry.IsRarV3` property and added `FileHeader.CompressionAlgorithm == 20 || FileHeader.CompressionAlgorithm == 26` to the logic. This forces it to use the UnpackV1 code rather than UnpackV2017. This fixes it. This PR also includes the UnitTests and Archives. Hopefully it will be useful I think it fixes this issue also: https://github.com/adamhathcock/sharpcompress/issues/619 Thanks. --- <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:08 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1135