From 70fc9f4b88841554f503e94c2c8099284abf97ad Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Tue, 24 Sep 2024 00:34:16 +0200 Subject: [PATCH 1/2] Work around crash being investigated --- Sources/ZIPFoundation/Data+Serialization.swift | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Sources/ZIPFoundation/Data+Serialization.swift b/Sources/ZIPFoundation/Data+Serialization.swift index 12340f90..4ec86010 100644 --- a/Sources/ZIPFoundation/Data+Serialization.swift +++ b/Sources/ZIPFoundation/Data+Serialization.swift @@ -29,12 +29,9 @@ extension Data { } func scanValue(start: Int) -> T { - let subdata = self.subdata(in: start...size) - #if swift(>=5.0) - return subdata.withUnsafeBytes { $0.load(as: T.self) } - #else - return subdata.withUnsafeBytes { $0.pointee } - #endif + return self.withUnsafeBytes() { + $0.loadUnaligned(fromByteOffset: start, as: T.self) + } } static func readStruct(from file: FILEPointer, at offset: UInt64) From c1ce2fb03473eee23f44d483f14ed39fe7141ff8 Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Mon, 30 Sep 2024 23:25:23 +0200 Subject: [PATCH 2/2] Fix lint violation --- Sources/ZIPFoundation/Data+Serialization.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ZIPFoundation/Data+Serialization.swift b/Sources/ZIPFoundation/Data+Serialization.swift index 4ec86010..59a8db15 100644 --- a/Sources/ZIPFoundation/Data+Serialization.swift +++ b/Sources/ZIPFoundation/Data+Serialization.swift @@ -29,7 +29,7 @@ extension Data { } func scanValue(start: Int) -> T { - return self.withUnsafeBytes() { + return self.withUnsafeBytes { $0.loadUnaligned(fromByteOffset: start, as: T.self) } }