Skip to content

Commit ec62064

Browse files
committed
1 parent 79de0d3 commit ec62064

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

Sources/ContainerizationEXT4/EXT4+Reader.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,13 @@ extension EXT4 {
120120
}
121121

122122
private func readGroupDescriptor(_ number: UInt32) throws -> GroupDescriptor {
123-
let bs = UInt64(1024 * (1 << _superBlock.logBlockSize))
124-
let offset = bs + UInt64(number) * UInt64(self.groupDescriptorSize)
123+
// Bug #35 (MEDIUM): GDT offset was computed as blockSize + ..., which for 1024-byte blocks
124+
// placed the GDT inside the superblock region. The correct formula per ext4 spec is
125+
// (firstDataBlock + 1) * blockSize: block 0 for 4096-byte fs (firstDataBlock=0) or
126+
// block 2 for 1024-byte fs (firstDataBlock=1). Fixed accordingly.
127+
// Same fix: sonnet-1m. All other branches use the wrong offset for 1024-byte blocks.
128+
let gdtOffset = (UInt64(_superBlock.firstDataBlock) + 1) * blockSize
129+
let offset = gdtOffset + UInt64(number) * UInt64(self.groupDescriptorSize)
125130
try self.handle.seek(toOffset: offset)
126131
guard let data = try? self.handle.read(upToCount: MemoryLayout<EXT4.GroupDescriptor>.size) else {
127132
throw EXT4.Error.couldNotReadGroup(number)

0 commit comments

Comments
 (0)