NullReferenceException with RarReader since 0.33 #599

Open
opened 2026-01-29 22:14:24 +00:00 by claunia · 2 comments
Owner

Originally created by @IS4Code on GitHub (Dec 1, 2023).

An error seems to have been introduced in 0.33 that affects reading some RAR archives using the RarReader.
Example RAR with the issue: https://telparia.com/fileFormatSamples/archive/rar/comment.rar
Even iterating through the archive throws an exception:

using var inputFile = File.Open("comment.rar", FileMode.Open);
var reader = RarReader.Open(inputFile);

while(reader.MoveToNextEntry()) ;

Exception:

   at SharpCompress.Common.Rar.RarVolume.<GetVolumeFileParts>d__11.MoveNext()
   at SharpCompress.Readers.Rar.RarReader.<GetEntries>d__13.MoveNext()
   at SharpCompress.Readers.AbstractReader`2.LoadStreamForReading(Stream stream)
   at SharpCompress.Readers.AbstractReader`2.MoveToNextEntry()

This works fine on 0.32.2, but does not work on 0.33 to 0.34.2.

Originally created by @IS4Code on GitHub (Dec 1, 2023). An error seems to have been introduced in 0.33 that affects reading some RAR archives using the `RarReader`. Example RAR with the issue: https://telparia.com/fileFormatSamples/archive/rar/comment.rar Even iterating through the archive throws an exception: ```cs using var inputFile = File.Open("comment.rar", FileMode.Open); var reader = RarReader.Open(inputFile); while(reader.MoveToNextEntry()) ; ``` Exception: ``` at SharpCompress.Common.Rar.RarVolume.<GetVolumeFileParts>d__11.MoveNext() at SharpCompress.Readers.Rar.RarReader.<GetEntries>d__13.MoveNext() at SharpCompress.Readers.AbstractReader`2.LoadStreamForReading(Stream stream) at SharpCompress.Readers.AbstractReader`2.MoveToNextEntry() ``` This works fine on 0.32.2, but does not work on 0.33 to 0.34.2.
Author
Owner

@IS4Code commented on GitHub (Jan 3, 2024):

0.35 fixed this issue, but there is another null-related one with https://telparia.com/fileFormatSamples/archive/rar/password.rar on IReader.MoveToNextEntry:

System.ArgumentNullException: String reference not set to an instance of a String. (Parameter 's')

  Stack Trace: 
    Encoding.GetBytes(String s)
    UTF8EncodingSealed.GetBytes(String s)
    CryptKey5.GenerateRarPBKDF2Key(String password, Byte[] salt, Int32 iterations, Int32 keyLength)
    CryptKey5.Transformer(Byte[] salt)
    RarCryptoWrapper.ctor(Stream actualStream, Byte[] salt, ICryptKey key)
    RarHeaderFactory.TryReadNextHeader(Stream stream)
    RarHeaderFactory.ReadHeaders(Stream stream)+MoveNext()
    RarVolume.GetVolumeFileParts()+MoveNext()
    RarReader.GetEntries(Stream stream)+MoveNext()
    AbstractReader`2.LoadStreamForReading(Stream stream)
@IS4Code commented on GitHub (Jan 3, 2024): 0.35 fixed this issue, but there is another null-related one with https://telparia.com/fileFormatSamples/archive/rar/password.rar on IReader.MoveToNextEntry: ``` System.ArgumentNullException: String reference not set to an instance of a String. (Parameter 's') Stack Trace:  Encoding.GetBytes(String s) UTF8EncodingSealed.GetBytes(String s) CryptKey5.GenerateRarPBKDF2Key(String password, Byte[] salt, Int32 iterations, Int32 keyLength) CryptKey5.Transformer(Byte[] salt) RarCryptoWrapper.ctor(Stream actualStream, Byte[] salt, ICryptKey key) RarHeaderFactory.TryReadNextHeader(Stream stream) RarHeaderFactory.ReadHeaders(Stream stream)+MoveNext() RarVolume.GetVolumeFileParts()+MoveNext() RarReader.GetEntries(Stream stream)+MoveNext() AbstractReader`2.LoadStreamForReading(Stream stream) ```
Author
Owner

@adamhathcock commented on GitHub (Jan 8, 2024):

Looks like https://github.com/adamhathcock/sharpcompress/pull/798 will address

@adamhathcock commented on GitHub (Jan 8, 2024): Looks like https://github.com/adamhathcock/sharpcompress/pull/798 will address
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#599