Compare commits

..

6 Commits

Author SHA1 Message Date
Adam Hathcock
b4bfde77d2 Version 0.10.2 2013-11-23 13:08:54 +00:00
Adam Hathcock
c4b005b3d4 Strong name Windows Store assembly 2013-11-23 11:13:01 +00:00
Adam Hathcock
c9d1f7b528 Updating with VS 2013 2013-11-23 11:10:22 +00:00
Adam Hathcock
21aa57945d Fix for byte counting 2013-11-23 11:10:07 +00:00
Adam Hathcock
1d0c7b6445 Added work around for invalid extended time format
https://sharpcompress.codeplex.com/workitem/42
2013-10-19 13:28:33 +01:00
Adam Hathcock
f33d8f9a5e Fixed deletion test 2013-10-19 13:21:37 +01:00
20 changed files with 109 additions and 107 deletions

View File

@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>sharpcompress</id>
<version>0.10.1.3</version>
<version>0.10.2</version>
<title>SharpCompress - Pure C# Decompression/Compression</title>
<authors>Adam Hathcock</authors>
<owners>Adam Hathcock</owners>
@@ -12,11 +12,11 @@
<description>SharpCompress is a compression library for .NET/Mono/Silverlight/WP7/WindowsStore that can unrar, decompress 7zip, zip/unzip, tar/untar bzip2/unbzip2 and gzip/ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip is implemented.</description>
<releaseNotes />
<language>en-US</language>
<tags>rar unrar zip unzip bzip2 gzip tar 7zip .net40 .net35 sl4</tags>
<tags>rar unrar zip unzip bzip2 gzip tar 7zip</tags>
</metadata>
<files>
<file src="..\bin\Full\SharpCompress.dll" target="lib\net40\SharpCompress.dll" />
<file src="..\bin\WindowsStore\SharpCompress.dll" target="lib\netcore45\SharpCompress.dll" />
<file src="..\bin\Portable\SharpCompress.dll" target="lib\portable-net4+sl4+wp7+win8\SharpCompress.dll" />
<file src="..\bin\Portable\SharpCompress.dll" target="lib\portable-net4+sl5+wp8+win8\SharpCompress.dll" />
</files>
</package>

View File

@@ -21,6 +21,14 @@ TODOs (always lots):
* Zip64
* Multi-volume Zip support.
Version 0.10.2:
==============
- Fixed Rar Header reading for invalid extended time headers.
- Windows Store assembly is now strong named
- Known issues with Long Tar names being worked on
- Updated to VS2013
- Portable targets SL5 and Windows Phone 8 (up from SL4 and WP7)
Version 0.10.1:
==============
- Fixed 7Zip extraction performance problem

View File

@@ -15,12 +15,30 @@ namespace SharpCompress.Test
{
ArchiveStreamRead("Rar.none.rar");
}
[TestMethod]
public void Rar_ArchiveStreamRead()
{
ArchiveStreamRead("Rar.rar");
}
[TestMethod]
public void Rar_test_invalid_exttime_ArchiveStreamRead()
{
ResetScratch();
using (var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "test_invalid_exttime.rar")))
{
using (var archive = ArchiveFactory.Open(stream))
{
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
{
entry.WriteToDirectory(SCRATCH_FILES_PATH, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);
}
}
}
}
[TestMethod]
public void Rar_Jpg_ArchiveStreamRead()
{

View File

@@ -50,15 +50,18 @@ namespace SharpCompress.Test
{
File.Copy(Path.Combine(TEST_ARCHIVES_PATH, file), Path.Combine(SCRATCH2_FILES_PATH, file));
}
using (var reader = RarReader.Open(testArchives.Select(s => Path.Combine(SCRATCH2_FILES_PATH, s))
.Select(p => File.OpenRead(p)), Options.None))
var streams = testArchives.Select(s => Path.Combine(SCRATCH2_FILES_PATH, s)).Select(File.OpenRead).ToList();
using (var reader = RarReader.Open(streams))
{
while (reader.MoveToNextEntry())
{
reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);
}
}
foreach (var stream in streams)
{
stream.Dispose();
}
VerifyFiles();
foreach (var file in testArchives.Select(s => Path.Combine(SCRATCH2_FILES_PATH, s)))

View File

@@ -61,17 +61,6 @@ namespace SharpCompress.Test
ArchiveFileRead("7Zip.BZip2.7z");
}
[TestMethod]
public void SevenZipArchive_LZMA2_SFX_PathRead()
{
ArchiveFileRead("7Zip.LZMA2.sfx.exe");
}
[TestMethod]
public void SevenZipArchive_LZMA2_SFX_StreamRead() {
ArchiveStreamRead("7Zip.LZMA2.sfx.exe");
}
[TestMethod]
[ExpectedException(typeof(IndexOutOfRangeException))]

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
@@ -11,13 +10,12 @@ namespace SharpCompress.Test
{
public class TestBase
{
//protected const string TEST_BASE_PATH = @"C:\Git\sharpcompress";
protected static string TEST_BASE_PATH=null;
protected static string TEST_ARCHIVES_PATH;
protected static string ORIGINAL_FILES_PATH;
protected static string MISC_TEST_FILES_PATH;
protected static string SCRATCH_FILES_PATH;
protected static string SCRATCH2_FILES_PATH;
protected const string TEST_BASE_PATH = @"C:\Git\sharpcompress";
protected static readonly string TEST_ARCHIVES_PATH = Path.Combine(TEST_BASE_PATH, "TestArchives", "Archives");
protected static readonly string ORIGINAL_FILES_PATH = Path.Combine(TEST_BASE_PATH, "TestArchives", "Original");
protected static readonly string MISC_TEST_FILES_PATH = Path.Combine(TEST_BASE_PATH, "TestArchives", "MiscTest");
protected static readonly string SCRATCH_FILES_PATH = Path.Combine(TEST_BASE_PATH, "TestArchives", "Scratch");
protected static readonly string SCRATCH2_FILES_PATH = Path.Combine(TEST_BASE_PATH, "TestArchives", "Scratch2");
protected static IEnumerable<string> GetRarArchives()
{
@@ -154,26 +152,10 @@ namespace SharpCompress.Test
private static readonly object testLock = new object();
private TestContext ctx;
public TestContext TestContext {
get {
return ctx;
}
set {
ctx = value;
}
}
[TestInitialize]
public void TestSetup()
{
Monitor.Enter(testLock);
TEST_BASE_PATH = Path.GetDirectoryName(Path.GetDirectoryName(ctx.TestDir));
TEST_ARCHIVES_PATH = Path.Combine(TEST_BASE_PATH, "TestArchives", "Archives");
ORIGINAL_FILES_PATH = Path.Combine(TEST_BASE_PATH, "TestArchives", "Original");
MISC_TEST_FILES_PATH = Path.Combine(TEST_BASE_PATH, "TestArchives", "MiscTest");
SCRATCH_FILES_PATH = Path.Combine(TEST_BASE_PATH, "TestArchives", "Scratch");
SCRATCH2_FILES_PATH = Path.Combine(TEST_BASE_PATH, "TestArchives", "Scratch2");
}
[TestCleanup]

View File

@@ -1,6 +1,15 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Testing", "Testing", "{932BBFCC-76E3-45FF-90CA-6BE4FBF4A097}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F18F1765-4A02-42FD-9BEF-F0E2FCBD9D17}"
ProjectSection(SolutionItems) = preProject
NuGet\sharpcompress.nuspec = NuGet\sharpcompress.nuspec
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpCompress", "SharpCompress\SharpCompress.csproj", "{10A689CF-76A2-4A4F-96E4-553C33398438}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpCompress.Test", "SharpCompress.Test\SharpCompress.Test.csproj", "{15679D7A-F22C-4943-87FF-BF5C76C4A6FD}"
@@ -13,13 +22,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpCompress.PortableTest"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpCompress.Test.Portable", "SharpCompress.Test\SharpCompress.Test.Portable.csproj", "{E9C3C94B-FB27-4B4F-B225-57513C254D37}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Testing", "Testing", "{932BBFCC-76E3-45FF-90CA-6BE4FBF4A097}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F18F1765-4A02-42FD-9BEF-F0E2FCBD9D17}"
ProjectSection(SolutionItems) = preProject
NuGet\sharpcompress.nuspec = NuGet\sharpcompress.nuspec
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -55,8 +57,8 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{15679D7A-F22C-4943-87FF-BF5C76C4A6FD} = {932BBFCC-76E3-45FF-90CA-6BE4FBF4A097}
{EFDCAF57-FD4D-4E5D-A3D5-F26B875817ED} = {932BBFCC-76E3-45FF-90CA-6BE4FBF4A097}
{E9C3C94B-FB27-4B4F-B225-57513C254D37} = {932BBFCC-76E3-45FF-90CA-6BE4FBF4A097}
{15679D7A-F22C-4943-87FF-BF5C76C4A6FD} = {932BBFCC-76E3-45FF-90CA-6BE4FBF4A097}
EndGlobalSection
EndGlobal

View File

@@ -43,12 +43,10 @@ namespace SharpCompress.Archive
return TarArchive.Open(stream, options);
}
stream.Seek(0, SeekOrigin.Begin);
if (SevenZipArchive.IsSevenZipFile(stream))
{
long offset = SevenZipArchive.FindSignature(stream);
if (offset > -1) {
stream.Seek(offset, SeekOrigin.Begin);
return SevenZipArchive.Open(stream, options);
}
stream.Seek(0, SeekOrigin.Begin);
return SevenZipArchive.Open(stream, options);
}
stream.Seek(0, SeekOrigin.Begin);
if (GZipArchive.IsGZipFile(stream))

View File

@@ -145,7 +145,7 @@ namespace SharpCompress.Archive.SevenZip
{
if (database == null)
{
stream.Seek(FindSignature(stream),SeekOrigin.Begin);
stream.Position = 0;
var reader = new ArchiveReader();
reader.Open(stream);
database = reader.ReadDatabase(null);
@@ -157,7 +157,7 @@ namespace SharpCompress.Archive.SevenZip
{
try
{
return FindSignature(stream)>-1;
return SignatureMatch(stream);
}
catch
{
@@ -165,27 +165,13 @@ namespace SharpCompress.Archive.SevenZip
}
}
private static readonly byte[] SIGNATURE = {(byte) '7', (byte) 'z', 0xBC, 0xAF, 0x27, 0x1C};
const int MAX_BYTES_TO_ARCHIVE = 0x40000;
public static long FindSignature(Stream stream){
private static readonly byte[] SIGNATURE = new byte[] {(byte) '7', (byte) 'z', 0xBC, 0xAF, 0x27, 0x1C};
private static bool SignatureMatch(Stream stream)
{
BinaryReader reader = new BinaryReader(stream);
int j = 0;
long match=-1;
var maxPos = Math.Min(MAX_BYTES_TO_ARCHIVE+SIGNATURE.Length, stream.Length);
for (; stream.Position < maxPos; ) {
var bt = reader.ReadByte();
if (bt == SIGNATURE[j]){
if (j == SIGNATURE.Length-1){
match = stream.Position - j-1;
break;
}
j++;
continue;
}
j = 0;
}
return match;
byte[] signatureBytes = reader.ReadBytes(6);
return signatureBytes.BinaryEquals(SIGNATURE);
}
protected override IReader CreateReaderForSolidExtraction()

View File

@@ -10,10 +10,10 @@ using System.Runtime.CompilerServices;
[assembly: AssemblyProduct("SharpCompress")]
[assembly:
InternalsVisibleTo(
"SharpCompress.Test"
"SharpCompress.Test, PublicKey=002400000480000094000000060200000024000052534131000400000100010005d6ae1b0f6875393da83c920a5b9408f5191aaf4e8b3c2c476ad2a11f5041ecae84ce9298bc4c203637e2fd3a80ad5378a9fa8da1363e98cea45c73969198a4b64510927c910001491cebbadf597b22448ad103b0a4007e339faf8fe8665dcdb70d65b27ac05b1977c0655fad06b372b820ecbdccf10a0f214fee0986dfeded"
)]
[assembly:
InternalsVisibleTo(
"SharpCompress.Test.Portable"
"SharpCompress.Test.Portable, PublicKey=002400000480000094000000060200000024000052534131000400000100010005d6ae1b0f6875393da83c920a5b9408f5191aaf4e8b3c2c476ad2a11f5041ecae84ce9298bc4c203637e2fd3a80ad5378a9fa8da1363e98cea45c73969198a4b64510927c910001491cebbadf597b22448ad103b0a4007e339faf8fe8665dcdb70d65b27ac05b1977c0655fad06b372b820ecbdccf10a0f214fee0986dfeded"
)]
#endif

View File

@@ -1,6 +1,5 @@
using System;
using System.IO;
using System.Text;
using SharpCompress.IO;
namespace SharpCompress.Common.Rar.Headers
@@ -15,7 +14,7 @@ namespace SharpCompress.Common.Rar.Headers
{
uint lowUncompressedSize = reader.ReadUInt32();
HostOS = (HostOS) (int) reader.ReadByte();
HostOS = (HostOS)reader.ReadByte();
FileCRC = reader.ReadUInt32();
@@ -46,7 +45,7 @@ namespace SharpCompress.Common.Rar.Headers
CompressedSize = UInt32To64(highCompressedSize, AdditionalSize);
UncompressedSize = UInt32To64(highUncompressedkSize, lowUncompressedSize);
nameSize = nameSize > 4*1024 ? (short) (4*1024) : nameSize;
nameSize = nameSize > 4 * 1024 ? (short)(4 * 1024) : nameSize;
byte[] fileNameBytes = reader.ReadBytes(nameSize);
@@ -106,11 +105,16 @@ namespace SharpCompress.Common.Rar.Headers
}
if (FileFlags.HasFlag(FileFlags.EXTTIME))
{
ushort extendedFlags = reader.ReadUInt16();
FileLastModifiedTime = ProcessExtendedTime(extendedFlags, FileLastModifiedTime, reader, 0);
FileCreatedTime = ProcessExtendedTime(extendedFlags, null, reader, 1);
FileLastAccessedTime = ProcessExtendedTime(extendedFlags, null, reader, 2);
FileArchivedTime = ProcessExtendedTime(extendedFlags, null, reader, 3);
// verify that the end of the header hasn't been reached before reading the Extended Time.
// some tools incorrectly omit Extended Time despite specifying FileFlags.EXTTIME, which most parsers tolerate.
if (ReadBytes + reader.CurrentReadByteCount <= HeaderSize - 2)
{
ushort extendedFlags = reader.ReadUInt16();
FileLastModifiedTime = ProcessExtendedTime(extendedFlags, FileLastModifiedTime, reader, 0);
FileCreatedTime = ProcessExtendedTime(extendedFlags, null, reader, 1);
FileLastAccessedTime = ProcessExtendedTime(extendedFlags, null, reader, 2);
FileArchivedTime = ProcessExtendedTime(extendedFlags, null, reader, 3);
}
}
}
@@ -130,7 +134,7 @@ namespace SharpCompress.Common.Rar.Headers
private static DateTime? ProcessExtendedTime(ushort extendedFlags, DateTime? time, MarkingBinaryReader reader,
int i)
{
uint rmode = (uint) extendedFlags >> (3 - i)*4;
uint rmode = (uint)extendedFlags >> (3 - i) * 4;
if ((rmode & 8) == 0)
{
return null;
@@ -145,14 +149,14 @@ namespace SharpCompress.Common.Rar.Headers
time = time.Value.AddSeconds(1);
}
uint nanosecondHundreds = 0;
int count = (int) rmode & 3;
int count = (int)rmode & 3;
for (int j = 0; j < count; j++)
{
byte b = reader.ReadByte();
nanosecondHundreds |= (((uint) b) << ((j + 3 - count)*8));
nanosecondHundreds |= (((uint)b) << ((j + 3 - count) * 8));
}
//10^-7 to 10^-3
return time.Value.AddMilliseconds(nanosecondHundreds*Math.Pow(10, -4));
return time.Value.AddMilliseconds(nanosecondHundreds * Math.Pow(10, -4));
}
private static string ConvertPath(string path, HostOS os)
@@ -205,7 +209,7 @@ namespace SharpCompress.Common.Rar.Headers
internal FileFlags FileFlags
{
get { return (FileFlags) base.Flags; }
get { return (FileFlags)base.Flags; }
}
internal long CompressedSize { get; private set; }

View File

@@ -38,7 +38,7 @@ namespace SharpCompress.Common.Rar.Headers
protected virtual void ReadFromReader(MarkingBinaryReader reader)
{
HeadCRC = reader.ReadInt16();
HeaderType = (HeaderType)(int)(reader.ReadByte() & 0xff);
HeaderType = (HeaderType)(reader.ReadByte() & 0xff);
Flags = reader.ReadInt16();
HeaderSize = reader.ReadInt16();
if (FlagUtility.HasFlag(Flags, LONG_BLOCK))

View File

@@ -30,7 +30,6 @@ namespace SharpCompress.Common.Rar
public override byte[] ReadBytes(int count)
{
CurrentReadByteCount += count;
if (UseEncryption)
{
return ReadAndDecryptBytes(count);

View File

@@ -941,7 +941,6 @@ namespace SharpCompress.Common.SevenZip
#region Public Methods
const int HEADER_SIZE=0x20;
public void Open(Stream stream)
{
Close();
@@ -950,14 +949,13 @@ namespace SharpCompress.Common.SevenZip
_streamEnding = stream.Length;
// TODO: Check Signature!
_header = new byte[HEADER_SIZE];
int delta;
for (int offset = 0; offset < HEADER_SIZE; offset += delta)
_header = new byte[0x20];
for (int offset = 0; offset < 0x20; )
{
delta = stream.Read(_header, offset, HEADER_SIZE - offset);
int delta = stream.Read(_header, offset, 0x20 - offset);
if (delta == 0)
throw new EndOfStreamException("ArchiveReader.Open : unable to read");
throw new EndOfStreamException();
offset += delta;
}
_stream = stream;
@@ -997,7 +995,7 @@ namespace SharpCompress.Common.SevenZip
crc = CRC.Finish(crc);
if (crc != crcFromArchive)
throw new InvalidOperationException("Bad CRC");
throw new InvalidOperationException();
db.StartPositionAfterHeader = _streamOrigin + 0x20;

View File

@@ -12,7 +12,7 @@ namespace SharpCompress.IO
{
}
public long CurrentReadByteCount { get; protected set; }
public long CurrentReadByteCount { get; private set; }
public void Mark()
{

View File

@@ -9,12 +9,18 @@
<RootNamespace>SharpCompress</RootNamespace>
<AssemblyName>SharpCompress</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Profile1</TargetFrameworkProfile>
<TargetFrameworkProfile>Profile136</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\sharpcompress\</SolutionDir>
<BaseIntermediateOutputPath>obj\Portable\</BaseIntermediateOutputPath>
<RestorePackages>true</RestorePackages>
<MinimumVisualStudioVersion>10.0</MinimumVisualStudioVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>4.0</OldToolsVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>

View File

@@ -302,12 +302,21 @@
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<None Include="SharpCompress.pfx" />
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '11.0' ">
<VisualStudioVersion>11.0</VisualStudioVersion>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>SharpCompress.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("Copyright © Adam Hathcock")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("0.10.1.3")]
[assembly: AssemblyFileVersion("0.10.1.3")]
[assembly: AssemblyVersion("0.10.2.0")]
[assembly: AssemblyFileVersion("0.10.2.0")]

Binary file not shown.