Conversation
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 26 out of 26 changed files in this pull request and generated 58 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| return; | ||
| } | ||
| _isDisposed = true; |
There was a problem hiding this comment.
Duplicate assignment of _isDisposed = true. The field is already set to true on line 103, making this second assignment redundant and potentially confusing.
| _isDisposed = true; |
| } | ||
|
|
||
| var NewWindow = Fragmented ? null : new byte[WinSize]; | ||
| var NewWindow = Fragmented ? null : ArrayPool<byte>.Shared.Rent((int)WinSize); |
There was a problem hiding this comment.
ArrayPool.Shared.Rent() may return an array larger than requested. The code should track the actual WinSize separately and ensure only the required portion is used, or clear the entire rented array to avoid using uninitialized memory from the pool.
| var NewWindow = Fragmented ? null : ArrayPool<byte>.Shared.Rent((int)WinSize); | |
| var NewWindow = Fragmented ? null : ArrayPool<byte>.Shared.Rent((int)WinSize); | |
| if (NewWindow != null) | |
| { | |
| // Clear only the portion of the array that will be used. | |
| Array.Clear(NewWindow, 0, (int)WinSize); | |
| } |
| var array = System.Buffers.ArrayPool<byte>.Shared.Rent(buffer.Length); | ||
| try | ||
| { | ||
| var result = await base.ReadAsync(buffer, cancellationToken).ConfigureAwait(false); | ||
| if (result != 0) | ||
| { | ||
| currentCrc = RarCRC.CheckCrc(currentCrc, buffer.Span, 0, result); | ||
| } | ||
| else if ( | ||
| !disableCRC | ||
| && GetCrc() != BitConverter.ToUInt32(readStream.CurrentCrc, 0) | ||
| && buffer.Length != 0 | ||
| ) | ||
| { | ||
| // NOTE: we use the last FileHeader in a multipart volume to check CRC | ||
| throw new InvalidFormatException("file crc mismatch"); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| finally | ||
| { | ||
| System.Buffers.ArrayPool<byte>.Shared.Return(array); | ||
| } |
There was a problem hiding this comment.
The rented array is not used. The code rents an array but then calls base.ReadAsync(buffer, ...) with the original buffer, making the array allocation wasteful. Either use the rented array for the read operation or remove the unnecessary allocation.
| var array = System.Buffers.ArrayPool<byte>.Shared.Rent(buffer.Length); | |
| try | |
| { | |
| var result = await base.ReadAsync(buffer, cancellationToken).ConfigureAwait(false); | |
| if (result != 0) | |
| { | |
| currentCrc = RarCRC.CheckCrc(currentCrc, buffer.Span, 0, result); | |
| } | |
| else if ( | |
| !disableCRC | |
| && GetCrc() != BitConverter.ToUInt32(readStream.CurrentCrc, 0) | |
| && buffer.Length != 0 | |
| ) | |
| { | |
| // NOTE: we use the last FileHeader in a multipart volume to check CRC | |
| throw new InvalidFormatException("file crc mismatch"); | |
| } | |
| return result; | |
| } | |
| finally | |
| { | |
| System.Buffers.ArrayPool<byte>.Shared.Return(array); | |
| } | |
| var result = await base.ReadAsync(buffer, cancellationToken).ConfigureAwait(false); | |
| if (result != 0) | |
| { | |
| currentCrc = RarCRC.CheckCrc(currentCrc, buffer.Span, 0, result); | |
| } | |
| else if ( | |
| !disableCRC | |
| && GetCrc() != BitConverter.ToUInt32(readStream.CurrentCrc, 0) | |
| && buffer.Length != 0 | |
| ) | |
| { | |
| // NOTE: we use the last FileHeader in a multipart volume to check CRC | |
| throw new InvalidFormatException("file crc mismatch"); | |
| } | |
| return result; |
| if (Inp.InAddr > ReadTop - 25) | ||
| { | ||
| if (!await UnpReadBufAsync(cancellationToken).ConfigureAwait(false)) | ||
| { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
These 'if' statements can be combined.
| if (Inp.InAddr > ReadTop - 25) | |
| { | |
| if (!await UnpReadBufAsync(cancellationToken).ConfigureAwait(false)) | |
| { | |
| return false; | |
| } | |
| if (Inp.InAddr > ReadTop - 25 && !await UnpReadBufAsync(cancellationToken).ConfigureAwait(false)) | |
| { | |
| return false; |
| if (Inp.InAddr > ReadTop - 5) | ||
| { | ||
| if (!await UnpReadBufAsync(cancellationToken).ConfigureAwait(false)) | ||
| { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
These 'if' statements can be combined.
| if (Inp.InAddr > ReadTop - 5) | |
| { | |
| if (!await UnpReadBufAsync(cancellationToken).ConfigureAwait(false)) | |
| { | |
| return false; | |
| } | |
| if (Inp.InAddr > ReadTop - 5 && !await UnpReadBufAsync(cancellationToken).ConfigureAwait(false)) | |
| { | |
| return false; |
| var fltj = Filters[J]; | ||
| if ( | ||
| fltj.Type != FILTER_NONE | ||
| && fltj.NextWindow == false |
There was a problem hiding this comment.
The expression 'A == false' can be simplified to '!A'.
| && fltj.NextWindow == false | |
| && !fltj.NextWindow |
| if (!reader.Entry.IsDirectory) | ||
| { | ||
| Assert.Equal(CompressionType.Rar, reader.Entry.CompressionType); | ||
| var entryStream = await reader.OpenEntryStreamAsync(); |
There was a problem hiding this comment.
This variable is manually disposed in a finally block - consider a C# using statement as a preferable resource management technique.
| RarStream stream; | ||
| if (IsRarV3) | ||
| { | ||
| stream = new RarStream( | ||
| archive.UnpackV1.Value, | ||
| FileHeader, | ||
| new MultiVolumeReadOnlyStream(Parts.Cast<RarFilePart>(), archive) | ||
| ); | ||
| } | ||
| else | ||
| { | ||
| stream = new RarStream( | ||
| archive.UnpackV2017.Value, | ||
| FileHeader, | ||
| new MultiVolumeReadOnlyStream(Parts.Cast<RarFilePart>(), archive) | ||
| ); | ||
| } |
There was a problem hiding this comment.
Both branches of this 'if' statement write to the same variable - consider using '?' to express intent better.
| RarStream stream; | |
| if (IsRarV3) | |
| { | |
| stream = new RarStream( | |
| archive.UnpackV1.Value, | |
| FileHeader, | |
| new MultiVolumeReadOnlyStream(Parts.Cast<RarFilePart>(), archive) | |
| ); | |
| } | |
| else | |
| { | |
| stream = new RarStream( | |
| archive.UnpackV2017.Value, | |
| FileHeader, | |
| new MultiVolumeReadOnlyStream(Parts.Cast<RarFilePart>(), archive) | |
| ); | |
| } | |
| RarStream stream = new RarStream( | |
| IsRarV3 ? archive.UnpackV1.Value : archive.UnpackV2017.Value, | |
| FileHeader, | |
| new MultiVolumeReadOnlyStream(Parts.Cast<RarFilePart>(), archive) | |
| ); |
|
@copilot figure out why the windows tests fail |
|
@adamhathcock I've opened a new pull request, #1000, to work on those changes. Once the pull request is ready, I'll request review from you. |
Part of #992