Skip to content

Commit 6a809b9

Browse files
authored
Fix miniStream iteration bug, add HWP test (#5)
The sector data truncation logic was checking the constant value passed to the `oleStream` function, instead of the incremented iteration index. Resolves #1.
1 parent 761a179 commit 6a809b9

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

Sources/OLEKit/OLEStream.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ extension Reader {
5959
// if sector is the last of the file, sometimes it is not a
6060
// complete sector (of 512 or 4K), so we may read less than
6161
// sectorsize.
62-
if sectorID == fat.count - 1 {
62+
if currentSectorID == fat.count - 1 {
6363
data.append(readDataToEnd())
6464
} else {
6565
data.append(readData(ofLength: Int(sectorSize)))

Tests/OLEKitTests/OLEKitTests.swift

+12
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,16 @@ final class OLEKitTests: XCTestCase {
100100
"\u{05}DocumentSummaryInformation",
101101
])
102102
}
103+
104+
func testHWP() throws {
105+
let url = URL(fileURLWithPath: #file)
106+
.deletingLastPathComponent()
107+
.appendingPathComponent("blank.hwp")
108+
let ole = try OLEFile(url.path)
109+
let fileHeaderStream = ole.root.children.first(where: { $0.name == "FileHeader" })!
110+
let reader = try ole.stream(fileHeaderStream)
111+
let data = reader.readData(ofLength: 32)
112+
let signature = String(data: data, encoding: .ascii)
113+
XCTAssertEqual(signature, "HWP Document File\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0")
114+
}
103115
}

Tests/OLEKitTests/blank.hwp

22 KB
Binary file not shown.

0 commit comments

Comments
 (0)