From a41fe890765f28531a02226201deefd0bc0961ae Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Thu, 14 May 2026 21:33:33 +0800 Subject: [PATCH] [Tests] Add a test for 7-zip container with large LZMA dictionary size --- SWCompression.xcodeproj/project.pbxproj | 4 ++++ Sources/LZMA/LZMAProperties.swift | 2 +- Tests/SevenZipTests.swift | 11 +++++++++++ Tests/Test Files | 2 +- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/SWCompression.xcodeproj/project.pbxproj b/SWCompression.xcodeproj/project.pbxproj index a874536f..d14c33a6 100644 --- a/SWCompression.xcodeproj/project.pbxproj +++ b/SWCompression.xcodeproj/project.pbxproj @@ -221,6 +221,7 @@ E609D7B6271AFAA400068E79 /* test_small_dict_B5_BD.lz4 in Resources */ = {isa = PBXBuildFile; fileRef = E609D7B3271AFAA400068E79 /* test_small_dict_B5_BD.lz4 */; }; E609D7B7271AFAA400068E79 /* test_small_dict_B5.lz4 in Resources */ = {isa = PBXBuildFile; fileRef = E609D7B4271AFAA400068E79 /* test_small_dict_B5.lz4 */; }; E60CBA8A26AF379200A20130 /* test_only_dir_header.tar in Resources */ = {isa = PBXBuildFile; fileRef = E60CBA8926AF379200A20130 /* test_only_dir_header.tar */; }; + E61055CF2FB3546600A684F6 /* test_lzma_big_dict.7z in Resources */ = {isa = PBXBuildFile; fileRef = E61055CE2FB3546600A684F6 /* test_lzma_big_dict.7z */; }; E631055927084D5D006EACC3 /* LZ4+Compress.swift in Sources */ = {isa = PBXBuildFile; fileRef = E631055827084D5D006EACC3 /* LZ4+Compress.swift */; }; E6421E8F271B54C6000359B6 /* test_7z_lz4.7z in Resources */ = {isa = PBXBuildFile; fileRef = E6421E8E271B54C6000359B6 /* test_7z_lz4.7z */; }; E644E11E2833AB2400EEFBAD /* minimal.gz in Resources */ = {isa = PBXBuildFile; fileRef = E644E11D2833AB2400EEFBAD /* minimal.gz */; }; @@ -525,6 +526,7 @@ E609D7B3271AFAA400068E79 /* test_small_dict_B5_BD.lz4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = test_small_dict_B5_BD.lz4; sourceTree = ""; }; E609D7B4271AFAA400068E79 /* test_small_dict_B5.lz4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = test_small_dict_B5.lz4; sourceTree = ""; }; E60CBA8926AF379200A20130 /* test_only_dir_header.tar */ = {isa = PBXFileReference; lastKnownFileType = archive.tar; path = test_only_dir_header.tar; sourceTree = ""; }; + E61055CE2FB3546600A684F6 /* test_lzma_big_dict.7z */ = {isa = PBXFileReference; lastKnownFileType = file; path = test_lzma_big_dict.7z; sourceTree = ""; }; E631055827084D5D006EACC3 /* LZ4+Compress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "LZ4+Compress.swift"; sourceTree = ""; }; E631055A27086132006EACC3 /* SWCompression.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; name = SWCompression.xctestplan; path = SWCompression.xcodeproj/SWCompression.xctestplan; sourceTree = SOURCE_ROOT; }; E6421E8E271B54C6000359B6 /* test_7z_lz4.7z */ = {isa = PBXFileReference; lastKnownFileType = file; path = test_7z_lz4.7z; sourceTree = ""; }; @@ -1046,6 +1048,7 @@ 06F066011FFB763300312A82 /* test_7z_bzip2.7z */, 06F066021FFB763300312A82 /* test_7z_deflate.7z */, E6421E8E271B54C6000359B6 /* test_7z_lz4.7z */, + E61055CE2FB3546600A684F6 /* test_lzma_big_dict.7z */, 06F066041FFB763300312A82 /* test_empty_file.7z */, 06F066051FFB763300312A82 /* test_empty_dir.7z */, 06F066061FFB763300312A82 /* test_win.7z */, @@ -1285,6 +1288,7 @@ 06F066671FFB763400312A82 /* test2.7z in Resources */, 062D591421248758003543BD /* test_delta_filter.xz in Resources */, 0698B10B2104E11200A7C551 /* test_gnu_inc_format.tar in Resources */, + E61055CF2FB3546600A684F6 /* test_lzma_big_dict.7z in Resources */, 06F0661F1FFB763300312A82 /* test3.answer in Resources */, 06F066281FFB763400312A82 /* test5.gz in Resources */, 064D01AC20FD077D00CAE058 /* test_unicode_ustar.tar in Resources */, diff --git a/Sources/LZMA/LZMAProperties.swift b/Sources/LZMA/LZMAProperties.swift index 340a586f..b47003c2 100644 --- a/Sources/LZMA/LZMAProperties.swift +++ b/Sources/LZMA/LZMAProperties.swift @@ -18,7 +18,7 @@ public struct LZMAProperties { public var pb: Int = 2 /** - Size of the dictionary. Default value is 1 << 24. + Size of the dictionary. Default value is `1 << 24`. - Note: Dictionary size cannot be less than 4096. In case of attempt to set it to the value less than 4096 it will be automatically set to 4096 instead. diff --git a/Tests/SevenZipTests.swift b/Tests/SevenZipTests.swift index 41fa5e89..ba3a9ad3 100644 --- a/Tests/SevenZipTests.swift +++ b/Tests/SevenZipTests.swift @@ -343,6 +343,17 @@ class SevenZipTests: XCTestCase { XCTAssertEqual(entries[1].data, "Hello, Windows!".data(using: .utf8)) } + func test7z_LzmaBigDict() throws { + // Verifying the issue fixed by PR #61. + // Previously, there was a crash, if LZMA dictionary size was encoded using all 4 bytes. + let testData = try Constants.data(forTest: "test_lzma_big_dict", withType: SevenZipTests.testType) + let entries = try SevenZipContainer.open(container: testData) + XCTAssertEqual(entries.count, 1) + XCTAssertEqual(entries[0].info.name, "data") + XCTAssertEqual(entries[0].info.type, .regular) + XCTAssertEqual(entries[0].info.size, 16 * 1024 * 1024) + } + func testEmptyFile() throws { let testData = try Constants.data(forTest: "test_empty_file", withType: SevenZipTests.testType) let entries = try SevenZipContainer.open(container: testData) diff --git a/Tests/Test Files b/Tests/Test Files index ceb9715d..fae11e64 160000 --- a/Tests/Test Files +++ b/Tests/Test Files @@ -1 +1 @@ -Subproject commit ceb9715d24770ec80a80340ea7af2603a17b3a10 +Subproject commit fae11e64d12cf7c4e0788f6dbe7fadd19005ae8b