diff --git a/.jazzy.yaml b/.jazzy.yaml index 2a023beb..247e1986 100644 --- a/.jazzy.yaml +++ b/.jazzy.yaml @@ -1,13 +1,13 @@ # Run: sourcekitten doc --spm --module-name SWCompression > docs.json sourcekitten_sourcefile: docs.json -clean: true +clean: false author: Timofey Solomko module: SWCompression -module_version: 4.5.10 +module_version: 4.5.11 copyright: '© 2021 Timofey Solomko' readme: README.md github_url: https://github.com/tsolomko/SWCompression -github_file_prefix: https://github.com/tsolomko/SWCompression/tree/4.5.10 +github_file_prefix: https://github.com/tsolomko/SWCompression/tree/4.5.11 theme: fullwidth custom_categories: diff --git a/CHANGELOG.md b/CHANGELOG.md index d28dce1b..d47da297 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 4.5.11 + +- Fixed a crash when processing a truncated TAR file. +- Added missing documentation for `LZMAProperties.init()`. +- Windows is now supported. + ## 4.5.10 - Fixed compilation issues on Windows (PR #22 by @trametheka). diff --git a/README.md b/README.md index 413948ee..66acac23 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ SWCompression — is a framework with a collection of functions for: 2. Reading (and sometimes writing) archives of different formats. 3. Reading (and sometimes writing) containers such as ZIP, TAR and 7-Zip. -It also works both on Apple platforms and __Linux__. +It also works on Apple platforms, Linux, __and Windows__. All features are listed in the tables below. "TBD" means that feature is planned but not implemented (yet). @@ -193,14 +193,12 @@ If you want to run tests on your computer, you need to do an additional step aft ``` The argument of this function is an operating system that you're using. This command will download files used in tests, -and on macOS it will also try to download BitByteData dependency, which requires having Carthage installed. - -Currently, the Carthage part of this procedure may fail when using Xcode 12 or later. In that case you should manually -run `carthage update --use-xcframeworks --no-use-binaries` or use -[xconfig workaround](https://github.com/Carthage/Carthage/blob/master/Documentation/Xcode12Workaround.md). Please also -note that when on working on SWCompression in Xcode when building the project you may see ld warnings about a directory -not being found. These are expected and harmless. Finally, you should keep in mind that support for non-xcframework method -of installing dependencies is likely to be dropped in the future major update. +and on macOS it will also try to download BitByteData dependency, which requires having Carthage installed. When using +Xcode 12 or later, you should also pass the `--xcf` option, or use the +[xconfig workaround](https://github.com/Carthage/Carthage/blob/master/Documentation/Xcode12Workaround.md). +Please also note that when working on SWCompression in Xcode when building the project you may see ld warnings about a +directory not being found. These are expected and harmless. Finally, you should keep in mind that support for non-xcframework +method of installing dependencies is likely to be dropped in the future major update. Test files are stored in a [separate repository](https://github.com/tsolomko/SWCompression-Test-Files), using Git LFS. There are two reasons for this complicated setup. Firstly, some of these files can be quite big, and it would be @@ -233,9 +231,6 @@ completely in Swift without Objective-C, it can also be used on __Linux__. ## Future plans -See [5.0 Update](https://github.com/tsolomko/SWCompression/projects/2) Project for the list of planned API changes and -new features. - - Performance... - Better Deflate compression. - Something else... @@ -249,7 +244,7 @@ new features. - [pyflate](http://www.paul.sladen.org/projects/pyflate/) - [Deflate specification](https://www.ietf.org/rfc/rfc1951.txt) - [GZip specification](https://www.ietf.org/rfc/rfc1952.txt) -- [Zlib specfication](https://www.ietf.org/rfc/rfc1950.txt) +- [Zlib specification](https://www.ietf.org/rfc/rfc1950.txt) - [LZMA SDK and specification](http://www.7-zip.org/sdk.html) - [XZ specification](http://tukaani.org/xz/xz-file-format-1.0.4.txt) - [Wikipedia article about LZMA](https://en.wikipedia.org/wiki/Lempel–Ziv–Markov_chain_algorithm) diff --git a/SWCompression.podspec b/SWCompression.podspec index 21773455..a31fcf18 100644 --- a/SWCompression.podspec +++ b/SWCompression.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "SWCompression" - s.version = "4.5.10" + s.version = "4.5.11" s.summary = "A framework with functions for working with compression, archives and containers." s.description = "A framework with (de)compression algorithms and functions for processing various archives and containers." diff --git a/SWCompression.xcodeproj/SWCompression.plist b/SWCompression.xcodeproj/SWCompression.plist index dc55faec..29025807 100644 --- a/SWCompression.xcodeproj/SWCompression.plist +++ b/SWCompression.xcodeproj/SWCompression.plist @@ -15,9 +15,9 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 4.5.10 + 4.5.11 CFBundleVersion - 77 + 78 NSHumanReadableCopyright Copyright © 2021 Timofey Solomko diff --git a/SWCompression.xcodeproj/TestSWCompression.plist b/SWCompression.xcodeproj/TestSWCompression.plist index 1b2400fd..c6fd15cd 100644 --- a/SWCompression.xcodeproj/TestSWCompression.plist +++ b/SWCompression.xcodeproj/TestSWCompression.plist @@ -15,8 +15,8 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 4.5.10 + 4.5.11 CFBundleVersion - 77 + 78 diff --git a/SWCompression.xcodeproj/project.pbxproj b/SWCompression.xcodeproj/project.pbxproj index 9a4dae45..cb1511c6 100644 --- a/SWCompression.xcodeproj/project.pbxproj +++ b/SWCompression.xcodeproj/project.pbxproj @@ -1258,7 +1258,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CURRENT_PROJECT_VERSION = 77; + CURRENT_PROJECT_VERSION = 78; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -1339,7 +1339,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CURRENT_PROJECT_VERSION = 77; + CURRENT_PROJECT_VERSION = 78; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_STRICT_OBJC_MSGSEND = YES; "FRAMEWORK_SEARCH_PATHS[sdk=appletvos*]" = ( @@ -1400,7 +1400,7 @@ APPLICATION_EXTENSION_API_ONLY = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 77; + DYLIB_CURRENT_VERSION = 78; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = SWCompression.xcodeproj/SWCompression.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -1427,7 +1427,7 @@ APPLICATION_EXTENSION_API_ONLY = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 77; + DYLIB_CURRENT_VERSION = 78; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = SWCompression.xcodeproj/SWCompression.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; diff --git a/Sources/LZMA/LZMAProperties.swift b/Sources/LZMA/LZMAProperties.swift index 98425e02..5656b17f 100644 --- a/Sources/LZMA/LZMAProperties.swift +++ b/Sources/LZMA/LZMAProperties.swift @@ -43,6 +43,7 @@ public struct LZMAProperties { self.dictionarySize = dictionarySize } + /// Initializes LZMA properties with default values of lc, lp, pb, and dictionary size. public init() { } init(lzmaByte: UInt8, _ dictSize: Int) throws { diff --git a/Sources/TAR/TarContainer.swift b/Sources/TAR/TarContainer.swift index ad3329f3..a8ede371 100644 --- a/Sources/TAR/TarContainer.swift +++ b/Sources/TAR/TarContainer.swift @@ -36,7 +36,8 @@ public class TarContainer: Container { */ public static func formatOf(container data: Data) throws -> Format { // TAR container should be at least 512 bytes long (when it contains only one header). - guard data.count >= 512 else { throw TarError.tooSmallFileIsPassed } + guard data.count >= 512 + else { throw TarError.tooSmallFileIsPassed } /// Object with input data which supports convenient work with bit shifts. var infoProvider = TarEntryInfoProvider(data) @@ -126,6 +127,12 @@ public class TarContainer: Container { } else { let dataStartIndex = entryInfo.blockStartIndex + 512 let dataEndIndex = dataStartIndex + entryInfo.size! + // Verify that data is not truncated. + // The data.startIndex inequality is strict since by this point at least one header (i.e. 512 bytes) + // has been processed. The data.endIndex inequality is strict since there must be a 1024 bytes-long EOF + // marker block which isn't included into any entry. + guard dataStartIndex > data.startIndex && dataEndIndex < data.endIndex + else { throw TarError.wrongField } let entryData = data.subdata(in: dataStartIndex.. [TarEntryInfo] { - // First, if the TAR container contains only header, it should be at least 512 bytes long. - // So we have to check this. - guard data.count >= 512 else { throw TarError.tooSmallFileIsPassed } + // TAR container should be at least 512 bytes long (when it contains only one header). + guard data.count >= 512 + else { throw TarError.tooSmallFileIsPassed } /// Object with input data which supports convenient work with bit shifts. var infoProvider = TarEntryInfoProvider(data) diff --git a/Sources/swcomp/main.swift b/Sources/swcomp/main.swift index 16d1931f..1eed34a8 100644 --- a/Sources/swcomp/main.swift +++ b/Sources/swcomp/main.swift @@ -7,7 +7,7 @@ import Foundation import SWCompression import SwiftCLI -let cli = CLI(name: "swcomp", version: "4.5.10", +let cli = CLI(name: "swcomp", version: "4.5.11", description: """ swcomp - a small command-line client for SWCompression framework. Serves as an example of SWCompression usage. diff --git a/Tests/Test Files b/Tests/Test Files index 25a663fd..b11a3090 160000 --- a/Tests/Test Files +++ b/Tests/Test Files @@ -1 +1 @@ -Subproject commit 25a663fdbeafc4047a6701c830cb7c16af0680a6 +Subproject commit b11a3090304037141155b6aab01ae49c94ee12bf diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e3abad7e..ca1d8c68 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -85,6 +85,84 @@ stages: swift build swift build -c release # Check Release build just in case. displayName: 'Build SPM Debug & Release' -# - stage: Deploy -# dependsOn: Test -# condition: startsWith(variables['Build.SourceBranch'], 'refs/tags') # Deploy on tags only + - job: windows + strategy: + matrix: + windowsSwift54: + imageName: 'windows-2019' + SWIFT_VERSION: '5.4.1' + pool: + vmImage: $(imageName) + variables: + DEVELOPER_DIR: 'C:\Library\Developer' + SDKROOT: 'C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk' + XCTEST_DIR: 'C:\Library\Developer\Platforms\Windows.platform\Developer\Library\XCTest-development' + SWIFTFLAGS: '--sdk $(SDKROOT)' + SWIFTTESTFLAGS: '-Xswiftc -I -Xswiftc $(XCTEST_DIR)\usr\lib\swift\windows\x86_64 -Xswiftc -L -Xswiftc $(XCTEST_DIR)\usr\lib\swift\windows -Xswiftc -sdk -Xswiftc $(SDKROOT)' + steps: + - task: BatchScript@1 + inputs: + filename: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/Tools/VsDevCmd.bat + arguments: -no_logo -arch=x64 -host_arch=x64 + modifyEnvironment: true + displayName: 'vsvarsall.bat' + - pwsh: Invoke-WebRequest -Uri https://swift.org/builds/swift-$(SWIFT_VERSION)-release/windows10/swift-$(SWIFT_VERSION)-RELEASE/swift-$(SWIFT_VERSION)-RELEASE-windows10.exe -OutFile swift-install.exe + displayName: 'Download Swift' + - task: BatchScript@1 + inputs: + filename: .\swift-install.exe + arguments: /install /quiet + modifyEnvironment: true + displayName: 'Install Swift' + - script: | + copy %SDKROOT%\usr\share\ucrt.modulemap "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap" + copy %SDKROOT%\usr\share\visualc.modulemap "%VCToolsInstallDir%\include\module.modulemap" + copy %SDKROOT%\usr\share\visualc.apinotes "%VCToolsInstallDir%\include\visualc.apinotes" + copy %SDKROOT%\usr\share\winsdk.modulemap "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap" + displayName: 'Configure SDK' + - script: | + set PATH=C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin;C:\Library\Swift-development\bin;C:\Library\icu-67\usr\bin;%PATH% + swift.exe --version + swift.exe build %SWIFTFLAGS% + swift.exe build -c release %SWIFTFLAGS% + displayName: 'Build SPM Debug & Release' +- stage: deploy + displayName: Deploy + dependsOn: test + # Deploy on tags only; test tags are excluded in trigger section. + condition: and(not(eq(variables['Build.Reason'], 'PullRequest')), startsWith(variables['Build.SourceBranch'], 'refs/tags')) + jobs: + - job: ghPages + displayName: 'Publish API docs to GH Pages' + pool: + vmImage: 'macOS-10.15' + variables: + DEVELOPER_DIR: '/Applications/Xcode_12.4.app' + steps: + - script: | + set -e -o xtrace + brew update + brew install sourcekitten + gem install -N jazzy + displayName: 'Install Tools' + - task: InstallSSHKey@0 + inputs: + knownHostsEntry: 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==' + sshPublicKey: '$(swcPubDeployKey)' + sshKeySecureFile: 'swc_deploy_key' + displayName: 'Install an SSH key' + - script: git worktree add docs gh-pages + displayName: 'Prepare Worktree' + - script: ./utils.py ci before-deploy + displayName: 'Before Deploy' + - script: | + set -e -o xtrace + git config --local user.name "Azure Pipelines" + git config --local user.email "azuredevops@microsoft.com" + cd docs + git add --all + git commit -m "Deploy to GH Pages [skip ci]" --amend + cd .. + git remote set-url --push origin git@github.com:tsolomko/SWCompression.git + git push --force origin gh-pages:gh-pages + displayName: 'Deploy to GH Pages'