Skip to content

Commit 586385f

Browse files
authored
Remove not used code which had a buffer overread (#629)
Removes not used `FilePath.init?(Data)` which had a buffer overread. It used `String(cString:)` which reads until `\0`, but `Data` is not null-terminated.
1 parent b36c63c commit 586385f

2 files changed

Lines changed: 2 additions & 17 deletions

File tree

Sources/ContainerizationEXT4/FilePath+Extensions.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,6 @@ extension FilePath {
5353
self.init(url.path(percentEncoded: false))
5454
}
5555

56-
public init?(_ data: Data) {
57-
let cstr: String? = data.withUnsafeBytes { (rbp: UnsafeRawBufferPointer) in
58-
guard let baseAddress = rbp.baseAddress else {
59-
return nil
60-
}
61-
62-
let cString = baseAddress.bindMemory(to: CChar.self, capacity: data.count)
63-
return String(cString: cString)
64-
}
65-
66-
guard let cstr else {
67-
return nil
68-
}
69-
self.init(cstr)
70-
}
71-
7256
public func join(_ path: FilePath) -> FilePath {
7357
self.pushing(path)
7458
}

Tests/ContainerizationEXT4Tests/TestFormatterUnpack.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ struct Tar2EXT4Test: ~Copyable {
138138

139139
let specialFileInode = try ext4.getInode(number: 20)
140140
let bytes = Data(Mirror(reflecting: specialFileInode.block).children.compactMap { $0.value as? UInt8 })
141-
let specialFileTarget = try #require(FilePath(bytes), "Could not parse special file path")
141+
let targetString = try #require(String(data: bytes, encoding: .utf8), "Could not parse special file path")
142+
let specialFileTarget = FilePath(targetString)
142143
#expect(specialFileTarget.description.hasPrefix("special_ĩ"))
143144
}
144145
}

0 commit comments

Comments
 (0)