@@ -160,6 +160,7 @@ func groupDescriptorFromBytes(b []byte, gdSize uint16, number int, checksumType
160160 copy (blockBitmapChecksum [0 :2 ], b [0x18 :0x1a ])
161161 copy (inodeBitmapChecksum [0 :2 ], b [0x1a :0x1c ])
162162 copy (unusedInodes [0 :2 ], b [0x1c :0x1e ])
163+ checksumInput := b [0x0 :0x20 ]
163164
164165 if gdSize == 64 {
165166 copy (blockBitmapLocation [4 :8 ], b [0x20 :0x24 ])
@@ -172,17 +173,10 @@ func groupDescriptorFromBytes(b []byte, gdSize uint16, number int, checksumType
172173 copy (snapshotExclusionBitmapLocation [4 :8 ], b [0x34 :0x38 ])
173174 copy (blockBitmapChecksum [2 :4 ], b [0x38 :0x3a ])
174175 copy (inodeBitmapChecksum [2 :4 ], b [0x3a :0x3c ])
176+ checksumInput = b [0x0 :0x40 ]
175177 }
176178
177179 gdNumber := uint16 (number )
178- // only bother with checking the checksum if it was not type none (pre-checksums)
179- if checksumType != gdtChecksumNone {
180- checksum := binary .LittleEndian .Uint16 (b [0x1e :0x20 ])
181- actualChecksum := groupDescriptorChecksum (b [0x0 :0x40 ], hashSeed , gdNumber , checksumType )
182- if checksum != actualChecksum {
183- return nil , fmt .Errorf ("checksum mismatch, passed %x, actual %x" , checksum , actualChecksum )
184- }
185- }
186180
187181 gd := groupDescriptor {
188182 size : gdSize ,
@@ -200,6 +194,15 @@ func groupDescriptorFromBytes(b []byte, gdSize uint16, number int, checksumType
200194 flags : parseBlockGroupFlags (binary .LittleEndian .Uint16 (b [0x12 :0x14 ])),
201195 }
202196
197+ // only bother with checking the checksum if it was not type none (pre-checksums)
198+ if checksumType != gdtChecksumNone {
199+ checksum := binary .LittleEndian .Uint16 (b [0x1e :0x20 ])
200+ actualChecksum := groupDescriptorChecksum (checksumInput , hashSeed , gdNumber , checksumType )
201+ if checksum != actualChecksum {
202+ return nil , fmt .Errorf ("checksum mismatch, passed %x, actual %x" , checksum , actualChecksum )
203+ }
204+ }
205+
203206 return & gd , nil
204207}
205208
0 commit comments