From 728d526a4f3df8993bbf37985988327b946c2646 Mon Sep 17 00:00:00 2001 From: Dmitry Kovba Date: Tue, 7 Apr 2026 15:00:23 -0700 Subject: [PATCH 1/2] Match the byte order in the EXT4 reader to how the EXT4 formatter writes data --- Sources/ContainerizationEXT4/EXT4+Reader.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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.. Date: Tue, 7 Apr 2026 15:32:18 -0700 Subject: [PATCH 2/2] Use the same little-endian read code throughout the EXT4 reader --- Sources/ContainerizationEXT4/EXT4+Extensions.swift | 8 ++++---- Sources/ContainerizationEXT4/EXT4+Xattrs.swift | 4 ++-- Sources/ContainerizationEXT4/EXT4Reader+Export.swift | 4 ++-- 3 files changed, 8 insertions(+), 8 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+Xattrs.swift b/Sources/ContainerizationEXT4/EXT4+Xattrs.swift index 6038ecd1..fe2d6e24 100644 --- a/Sources/ContainerizationEXT4/EXT4+Xattrs.swift +++ b/Sources/ContainerizationEXT4/EXT4+Xattrs.swift @@ -62,7 +62,7 @@ extension EXT4 { var i = 0 while i + 3 < value.count { let s = value[i..> 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 938cb1d6..77f8f997 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 }