Skip to content

Commit 0ceaa4c

Browse files
authored
Fixed a crash on Swift 6.0+ where Integer deserialization was assuming aligned memory (#1190)
### Motivation: The integer deserializer was assuming that the input raw memory was correctly aligned for the integer type to be deserialized. In the test that was true on some platforms, but not others. This caused a crash in the unit test. ### Modifications: Use `loadUnaligned` instead of `load` when loading integers. ### Result: Fixes #1179.
1 parent bcd8f8f commit 0ceaa4c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Sources/DistributedCluster/Serialization/Serialization+PrimitiveSerializers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ internal class IntegerSerializer<Number: FixedWidthInteger>: Serializer<Number>
7373
override func deserialize(from buffer: Serialization.Buffer) throws -> Number {
7474
switch buffer {
7575
case .data(let data):
76-
return Number(bigEndian: data.withUnsafeBytes { $0.load(as: Number.self) })
76+
return Number(bigEndian: data.withUnsafeBytes { $0.loadUnaligned(as: Number.self) })
7777
case .nioByteBuffer(let buffer):
7878
guard let i = buffer.getInteger(at: 0, endianness: .big, as: Number.self) else {
7979
throw SerializationError(.notAbleToDeserialize(hint: "\(buffer) as \(Number.self)"))

0 commit comments

Comments
 (0)