Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions internal/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 4 additions & 10 deletions internal/snapshot/snapshot_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}
Loading