From 74ac944790d7fa011253bc9cb2f3da1ce9a14df2 Mon Sep 17 00:00:00 2001 From: Dmitry Kovba Date: Thu, 9 Apr 2026 10:55:27 -0700 Subject: [PATCH] Match the byte order in the EXT4 reader to how the EXT4 formatter writes data (#664) Matches the byte order in the EXT4 reader to how the EXT4 formatter writes data. --- Sources/ContainerizationEXT4/EXT4+Extensions.swift | 8 ++++---- Sources/ContainerizationEXT4/EXT4+Reader.swift | 4 ++-- Sources/ContainerizationEXT4/EXT4+Xattrs.swift | 4 ++-- Sources/ContainerizationEXT4/EXT4Reader+Export.swift | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Sources/ContainerizationEXT4/EXT4+Extensions.swift b/Sources/ContainerizationEXT4/EXT4+Extensions.swift index c84a48a6..6442423c 100644 --- a/Sources/ContainerizationEXT4/EXT4+Extensions.swift +++ b/Sources/ContainerizationEXT4/EXT4+Extensions.swift @@ -76,16 +76,16 @@ extension EXT4.XAttrEntry { nameLength = bytes[0] nameIndex = bytes[1] let rawValue = Array(bytes[2...3]) - valueOffset = UInt16(littleEndian: rawValue.withUnsafeBytes { $0.load(as: UInt16.self) }) + valueOffset = rawValue.withUnsafeBytes { $0.loadLittleEndian(as: UInt16.self) } let rawValueInum = Array(bytes[4...7]) - valueInum = UInt32(littleEndian: rawValueInum.withUnsafeBytes { $0.load(as: UInt32.self) }) + valueInum = rawValueInum.withUnsafeBytes { $0.loadLittleEndian(as: UInt32.self) } let rawSize = Array(bytes[8...11]) - valueSize = UInt32(littleEndian: rawSize.withUnsafeBytes { $0.load(as: UInt32.self) }) + valueSize = rawSize.withUnsafeBytes { $0.loadLittleEndian(as: UInt32.self) } let rawHash = Array(bytes[12...]) - hash = UInt32(littleEndian: rawHash.withUnsafeBytes { $0.load(as: UInt32.self) }) + hash = rawHash.withUnsafeBytes { $0.loadLittleEndian(as: UInt32.self) } } } diff --git a/Sources/ContainerizationEXT4/EXT4+Reader.swift b/Sources/ContainerizationEXT4/EXT4+Reader.swift index 54274aa7..881c71ad 100644 --- a/Sources/ContainerizationEXT4/EXT4+Reader.swift +++ b/Sources/ContainerizationEXT4/EXT4+Reader.swift @@ -215,7 +215,7 @@ extension EXT4 { // When depth is 0 the extent header is followed by extent leaves for _ in 0..> 16) ^ v i += 4 } @@ -72,7 +72,7 @@ extension EXT4 { for (i, byte) in value[last...].enumerated() { buff[i] = byte } - let v = UInt32(littleEndian: buff.withUnsafeBytes { $0.load(as: UInt32.self) }) + let v = buff.withUnsafeBytes { $0.loadLittleEndian(as: UInt32.self) } hash = (hash << 16) ^ (hash >> 16) ^ v } return hash diff --git a/Sources/ContainerizationEXT4/EXT4Reader+Export.swift b/Sources/ContainerizationEXT4/EXT4Reader+Export.swift index ac5c1057..2fd4109f 100644 --- a/Sources/ContainerizationEXT4/EXT4Reader+Export.swift +++ b/Sources/ContainerizationEXT4/EXT4Reader+Export.swift @@ -169,7 +169,7 @@ extension EXT4.EXT4Reader { } public static func readInlineExtendedAttributes(from buffer: [UInt8]) throws -> [EXT4.ExtendedAttribute] { - let header = UInt32(littleEndian: buffer[0..<4].withUnsafeBytes { $0.load(as: UInt32.self) }) + let header = buffer[0..<4].withUnsafeBytes { $0.loadLittleEndian(as: UInt32.self) } if header != EXT4.XAttrHeaderMagic { throw EXT4.FileXattrsState.Error.missingXAttrHeader } @@ -182,7 +182,7 @@ extension EXT4.EXT4Reader { } public static func readBlockExtendedAttributes(from buffer: [UInt8]) throws -> [EXT4.ExtendedAttribute] { - let header = UInt32(littleEndian: buffer[0..<4].withUnsafeBytes { $0.load(as: UInt32.self) }) + let header = buffer[0..<4].withUnsafeBytes { $0.loadLittleEndian(as: UInt32.self) } if header != EXT4.XAttrHeaderMagic { throw EXT4.FileXattrsState.Error.missingXAttrHeader }