Skip to content

Commit 8d3ca24

Browse files
committed
[Tests] Add a test for BZip2 truncation handling
The idea here is that BZip2.decompress should not crash for any possible truncation. It should either throw an error or produce an output (if stars align such that truncated input is still a valid BZip2 "archive").
1 parent f307a7f commit 8d3ca24

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

Tests/BZip2Tests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,15 @@ class BZip2Tests: XCTestCase {
9696
}
9797
}
9898

99+
func testBZip2Truncation() throws {
100+
for i in 1...9 {
101+
let testName = "test\(i)"
102+
let testData = try Constants.data(forTest: testName, withType: BZip2Tests.testType)
103+
for _ in 0..<10 {
104+
let truncationIndex = Int.random(in: (testData.startIndex + 1)..<testData.endIndex)
105+
_ = try? BZip2.decompress(data: testData[testData.startIndex..<truncationIndex])
106+
}
107+
}
108+
}
109+
99110
}

0 commit comments

Comments
 (0)