An exception occurred in ReadOnlySubStream when attempting to set the position to the same value.

This commit is contained in:
Twan van Dongen
2025-03-11 18:57:52 +01:00
2 changed files with 4 additions and 12 deletions

View File

@@ -69,16 +69,8 @@ namespace SharpCompress.Common.Arc
public static DateTime ConvertToDateTime(long rawDateTime)
{
// Extract components using bit manipulation
int year = (int)((rawDateTime >> 25) & 0x7F) + 1980;
int month = (int)((rawDateTime >> 21) & 0xF);
int day = (int)((rawDateTime >> 16) & 0x1F);
int hour = (int)((rawDateTime >> 11) & 0x1F);
int minute = (int)((rawDateTime >> 5) & 0x3F);
int second = (int)((rawDateTime & 0x1F) * 2); // Multiply by 2 since DOS seconds are stored as halves
// Return as a DateTime object
return new DateTime(year, month, day, hour, minute, second);
// Convert Unix timestamp to DateTime (UTC)
return DateTimeOffset.FromUnixTimeSeconds(rawDateTime).UtcDateTime;
}
}
}

View File

@@ -13,7 +13,7 @@ internal class ReadOnlySubStream : NonDisposingStream
public ReadOnlySubStream(Stream stream, long? origin, long bytesToRead)
: base(stream, throwOnDispose: false)
{
if (origin != null)
if (origin != null && stream.Position != origin.Value)
{
stream.Position = origin.Value;
}
@@ -31,7 +31,7 @@ internal class ReadOnlySubStream : NonDisposingStream
public override void Flush() { }
public override long Length => throw new NotSupportedException();
public override long Length => base.Length;
public override long Position
{