adamhathcock / sharpcompress

SharpCompress is a fully managed C# library to deal with many compression types and formats.
MIT License
2.22k stars 476 forks source link

NullReferenceException with RarReader since 0.33 #783

Open IS4Code opened 7 months ago

IS4Code commented 7 months ago

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.

IS4Code commented 6 months ago

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)
adamhathcock commented 5 months ago

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