From bc06a9df8ba3f262a7a9a8231a0630872b22dd29 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Sat, 1 Aug 2026 12:43:44 +0100 Subject: [PATCH] Some clean up --- global.json | 2 +- .../Compressors/Rar/RarCrcStream.Async.cs | 15 ++++----- .../Compressors/Rar/RarCrcStream.cs | 33 ++++++++----------- src/SharpCompress/packages.lock.json | 12 +++---- .../SharpCompress.AotSmoke/packages.lock.json | 24 +++++++------- 5 files changed, 39 insertions(+), 47 deletions(-) diff --git a/global.json b/global.json index 8a7554cf..e784f38f 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "10.0.301", + "version": "10.0.302", "rollForward": "disable" } } \ No newline at end of file diff --git a/src/SharpCompress/Compressors/Rar/RarCrcStream.Async.cs b/src/SharpCompress/Compressors/Rar/RarCrcStream.Async.cs index 2aedc9a6..a76a9ed6 100644 --- a/src/SharpCompress/Compressors/Rar/RarCrcStream.Async.cs +++ b/src/SharpCompress/Compressors/Rar/RarCrcStream.Async.cs @@ -1,5 +1,4 @@ using System; -using System.IO; using System.Threading; using System.Threading.Tasks; using SharpCompress.Common; @@ -31,11 +30,11 @@ internal partial class RarCrcStream : RarStream .ConfigureAwait(false); if (result != 0) { - currentCrc = RarCRC.CheckCrc(currentCrc, buffer, offset, result); + _currentCrc = RarCRC.CheckCrc(_currentCrc, buffer, offset, result); } else if ( - !disableCRC - && GetCrc() != BitConverter.ToUInt32(readStream.NotNull().CurrentCrc.NotNull(), 0) + !_disableCrc + && GetCrc() != BitConverter.ToUInt32(_readStream.NotNull().CurrentCrc.NotNull(), 0) && count != 0 ) { @@ -56,16 +55,16 @@ internal partial class RarCrcStream : RarStream var result = await base.ReadAsync(buffer, cancellationToken).ConfigureAwait(false); if (result != 0) { - currentCrc = RarCRC.CheckCrc(currentCrc, buffer.Span, 0, result); + _currentCrc = RarCRC.CheckCrc(_currentCrc, buffer.Span, 0, result); } else if ( - !disableCRC - && GetCrc() != BitConverter.ToUInt32(readStream.NotNull().CurrentCrc.NotNull(), 0) + !_disableCrc + && GetCrc() != BitConverter.ToUInt32(_readStream.NotNull().CurrentCrc.NotNull(), 0) && buffer.Length != 0 ) { // NOTE: we use the last FileHeader in a multipart volume to check CRC - throw new InvalidFormatException("file crc mismatch"); + throw new InvalidFormatException("file crc mismatch: " + _key); } return result; diff --git a/src/SharpCompress/Compressors/Rar/RarCrcStream.cs b/src/SharpCompress/Compressors/Rar/RarCrcStream.cs index a9025e19..233b05be 100644 --- a/src/SharpCompress/Compressors/Rar/RarCrcStream.cs +++ b/src/SharpCompress/Compressors/Rar/RarCrcStream.cs @@ -1,7 +1,4 @@ using System; -using System.IO; -using System.Threading; -using System.Threading.Tasks; using SharpCompress.Common; using SharpCompress.Common.Rar.Headers; @@ -9,9 +6,10 @@ namespace SharpCompress.Compressors.Rar; internal partial class RarCrcStream : RarStream { - private readonly MultiVolumeReadOnlyStreamBase readStream; - private uint currentCrc; - private readonly bool disableCRC; + private readonly string? _key; + private readonly MultiVolumeReadOnlyStreamBase _readStream; + private uint _currentCrc; + private readonly bool _disableCrc; private RarCrcStream( IRarUnpack unpack, @@ -20,8 +18,9 @@ internal partial class RarCrcStream : RarStream ) : base(unpack, fileHeader, readStream) { - this.readStream = readStream; - disableCRC = fileHeader.IsEncrypted; + this._readStream = readStream; + _key = fileHeader.FileName; + _disableCrc = fileHeader.IsEncrypted; ResetCrc(); } @@ -36,31 +35,25 @@ internal partial class RarCrcStream : RarStream } // Async methods moved to RarCrcStream.Async.cs + public uint GetCrc() => ~_currentCrc; - protected override void Dispose(bool disposing) - { - base.Dispose(disposing); - } - - public uint GetCrc() => ~currentCrc; - - public void ResetCrc() => currentCrc = 0xffffffff; + public void ResetCrc() => _currentCrc = 0xffffffff; public override int Read(byte[] buffer, int offset, int count) { var result = base.Read(buffer, offset, count); if (result != 0) { - currentCrc = RarCRC.CheckCrc(currentCrc, buffer, offset, result); + _currentCrc = RarCRC.CheckCrc(_currentCrc, buffer, offset, result); } else if ( - !disableCRC - && GetCrc() != BitConverter.ToUInt32(readStream.NotNull().CurrentCrc.NotNull(), 0) + !_disableCrc + && GetCrc() != BitConverter.ToUInt32(_readStream.NotNull().CurrentCrc.NotNull(), 0) && count != 0 ) { // NOTE: we use the last FileHeader in a multipart volume to check CRC - throw new InvalidFormatException("file crc mismatch"); + throw new InvalidFormatException("file crc mismatch: " + _key); } return result; diff --git a/src/SharpCompress/packages.lock.json b/src/SharpCompress/packages.lock.json index 54571844..c49dccb6 100644 --- a/src/SharpCompress/packages.lock.json +++ b/src/SharpCompress/packages.lock.json @@ -321,9 +321,9 @@ "net10.0": { "Microsoft.NET.ILLink.Tasks": { "type": "Direct", - "requested": "[10.0.9, )", - "resolved": "10.0.9", - "contentHash": "4Iw41e2h7I4t70SJcX2GCmbyKJIlA273Cfm9RJMM050/3VBejGAG1KcthP5Z2L6SQcbfbf6BhNWO26+ZG+GzMg==" + "requested": "[10.0.10, )", + "resolved": "10.0.10", + "contentHash": "f5VCIE7AJpd5YvzNTeMGVzQIgyE9tX+AreTYwQF+REbu+DZo/2Ae+jNSwhPEYrVz6RRkd7y8ubXjk6Nn6Ka+Cg==" }, "Microsoft.NETFramework.ReferenceAssemblies": { "type": "Direct", @@ -441,9 +441,9 @@ "net8.0": { "Microsoft.NET.ILLink.Tasks": { "type": "Direct", - "requested": "[8.0.28, )", - "resolved": "8.0.28", - "contentHash": "XMqgVjlLxLqWmEh3c49haXLQwsMNtvo6YscUaqfvEGfg1iA8hnYgkUVq3i9Zu9gKeNKMWiiZKVwZExc/qyEAsQ==" + "requested": "[8.0.29, )", + "resolved": "8.0.29", + "contentHash": "HSBTfrkIZijz8z3ybLRKB7E8rHk4QQufFwpHa9fc5CMIgRhRzdn4mBGmlyXZqaueiMPtuJcnjresGvSTfaW8Mg==" }, "Microsoft.NETFramework.ReferenceAssemblies": { "type": "Direct", diff --git a/tests/SharpCompress.AotSmoke/packages.lock.json b/tests/SharpCompress.AotSmoke/packages.lock.json index 19031145..9e1690d2 100644 --- a/tests/SharpCompress.AotSmoke/packages.lock.json +++ b/tests/SharpCompress.AotSmoke/packages.lock.json @@ -4,15 +4,15 @@ "net10.0": { "Microsoft.DotNet.ILCompiler": { "type": "Direct", - "requested": "[10.0.9, )", - "resolved": "10.0.9", - "contentHash": "4y+VsQOcs4EiTSINdCpCWi/aLRbIbGTxSezQXd8uGVhzbDRm1FNVTZDyCUQixE0+g9UFusvfxVcF68YYz7RzxA==" + "requested": "[10.0.10, )", + "resolved": "10.0.10", + "contentHash": "tnG8ntt/Bk6odvHREnGLMo3PEiihy5iSlIFVp0JbIo00GKtNRt2k73eKZbPqR5yaJNIa3z8R86YLwbxfqpb17g==" }, "Microsoft.NET.ILLink.Tasks": { "type": "Direct", - "requested": "[10.0.9, )", - "resolved": "10.0.9", - "contentHash": "4Iw41e2h7I4t70SJcX2GCmbyKJIlA273Cfm9RJMM050/3VBejGAG1KcthP5Z2L6SQcbfbf6BhNWO26+ZG+GzMg==" + "requested": "[10.0.10, )", + "resolved": "10.0.10", + "contentHash": "f5VCIE7AJpd5YvzNTeMGVzQIgyE9tX+AreTYwQF+REbu+DZo/2Ae+jNSwhPEYrVz6RRkd7y8ubXjk6Nn6Ka+Cg==" }, "Microsoft.NETFramework.ReferenceAssemblies": { "type": "Direct", @@ -76,17 +76,17 @@ "net10.0/linux-x64": { "Microsoft.DotNet.ILCompiler": { "type": "Direct", - "requested": "[10.0.9, )", - "resolved": "10.0.9", - "contentHash": "4y+VsQOcs4EiTSINdCpCWi/aLRbIbGTxSezQXd8uGVhzbDRm1FNVTZDyCUQixE0+g9UFusvfxVcF68YYz7RzxA==", + "requested": "[10.0.10, )", + "resolved": "10.0.10", + "contentHash": "tnG8ntt/Bk6odvHREnGLMo3PEiihy5iSlIFVp0JbIo00GKtNRt2k73eKZbPqR5yaJNIa3z8R86YLwbxfqpb17g==", "dependencies": { - "runtime.linux-x64.Microsoft.DotNet.ILCompiler": "10.0.9" + "runtime.linux-x64.Microsoft.DotNet.ILCompiler": "10.0.10" } }, "runtime.linux-x64.Microsoft.DotNet.ILCompiler": { "type": "Transitive", - "resolved": "10.0.9", - "contentHash": "45CVefG8S0eUKUJ4LBWOi8FOAgMJOP6exW9l5M9OjvQaGR7jvkokBK50XaZCsO66uLxABcuzvncV8A3YiJLUgw==" + "resolved": "10.0.10", + "contentHash": "WRjSRBfv6A6UjgjO8EQuLe9xqdICpkQx1hACUziCw4B2uGL+2jVhkFLq/G7rxRr3MGvqLo9B+nNdfIJ/5CYN7A==" } } }