diff --git a/internal/snapshot/snapshot.go b/internal/snapshot/snapshot.go index 690178c1..5919cb68 100644 --- a/internal/snapshot/snapshot.go +++ b/internal/snapshot/snapshot.go @@ -179,7 +179,7 @@ type Descriptor struct { State State // Current state Flags Flags // Snapshot flags DataInode uint32 // Hidden inode holding the captured extents - TargetBirth uint64 // Birth generation of the snapshotted file, 48 bits + TargetBirth uint64 // Birth generation of the snapshotted file, 48 bits; without FlagHasTargetBirth, the bytes an older version left there TotalBlocks uint64 // Number of blocks at snapshot time TotalSize uint64 // File size at snapshot time CreateTime int64 // Creation timestamp @@ -902,12 +902,10 @@ func decodeDescriptor(sectorData []byte, descIdx uint64) (*Descriptor, error) { CreateTime: int64(binary.LittleEndian.Uint64(data[52:60])), DeleteTime: int64(binary.LittleEndian.Uint64(data[60:68])), RefCountJobID: binary.LittleEndian.Uint64(data[68:76]), + TargetBirth: uint64(binary.LittleEndian.Uint16(data[26:28]))<<32 | uint64(binary.LittleEndian.Uint32(data[32:36])), Checksum: stored, } copy(desc.Name[:], data[76:124]) - if desc.Flags&FlagHasTargetBirth != 0 { - desc.TargetBirth = uint64(binary.LittleEndian.Uint16(data[26:28]))<<32 | uint64(binary.LittleEndian.Uint32(data[32:36])) - } return desc, nil } diff --git a/internal/snapshot/snapshot_fuzz_test.go b/internal/snapshot/snapshot_fuzz_test.go index 9ab2a7e6..f88152c6 100644 --- a/internal/snapshot/snapshot_fuzz_test.go +++ b/internal/snapshot/snapshot_fuzz_test.go @@ -60,21 +60,15 @@ func FuzzDecodeDescriptor(f *testing.F) { func checkDescriptorDecode(t *testing.T, sector []byte, idx uint64) { desc, err := decodeDescriptor(sector, idx) - if err != nil { + if err != nil || desc.Magic == 0 { return } _ = desc.GetName() out := make([]byte, BytesPerSector) encodeDescriptor(out, 0, desc) - again, err := decodeDescriptor(out, 0) - if err != nil { - t.Fatalf("decoding a re-encoded descriptor: %v", err) - } - // Bytes only some formats use, such as the birth generation without - // FlagHasTargetBirth, re-encode as zero and change the checksum. - again.Checksum = desc.Checksum - if *again != *desc { - t.Fatalf("descriptor changed after an encode/decode round trip: %+v != %+v", again, desc) + in := sector[idx*DescriptorSize : (idx+1)*DescriptorSize] + if !bytes.Equal(out[:DescriptorSize], in) { + t.Fatalf("re-encoding a descriptor changed its bytes:\nread %x\nwrote %x", in, out[:DescriptorSize]) } }