Skip to content

Commit 0501c93

Browse files
committed
fix bug
1 parent d68dc09 commit 0501c93

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

storage/bbolt/dedup.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ func (s *Storage) Add(_ context.Context, ldis []dedup.LeafDedupInfo) error {
116116
return fmt.Errorf("vtob(): %v", err)
117117
}
118118

119+
// old should always be 16 bytes long, but double check
119120
if old := db.Get(ldi.LeafID); len(old) == 16 && btoi(old[:8]) <= ldi.Idx {
120-
klog.V(3).Infof("Add(): bucket %q already contains a smaller index %d < %d for entry %q, not updating", dedupBucket, btoi(old[:8]), ldi.Idx, hex.EncodeToString(ldi.LeafID))
121+
klog.V(3).Infof("Add(): bucket %q already contains a smaller index %d < %d for entry \"%x\", not updating", dedupBucket, btoi(old[:8]), ldi.Idx, ldi.LeafID)
121122
} else if err := db.Put(ldi.LeafID, vB); err != nil {
122123
return err
123124
}
@@ -148,7 +149,7 @@ func (s *Storage) Get(_ context.Context, leafID []byte) (dedup.SCTDedupInfo, boo
148149
b := tx.Bucket([]byte(dedupBucket))
149150
vv := b.Get(leafID)
150151
if vv != nil {
151-
v = make([]byte, 16)
152+
v = make([]byte, len(v))
152153
copy(v, vv)
153154
}
154155
return nil
@@ -196,7 +197,7 @@ func btoi(b []byte) uint64 {
196197

197198
// vtob concatenates an index and timestamp values into a byte array.
198199
func vtob(idx uint64, timestamp uint64) ([]byte, error) {
199-
b := make([]byte, 16)
200+
b := make([]byte, 0, 16)
200201
var err error
201202

202203
b, err = binary.Append(b, binary.BigEndian, idx)
@@ -214,6 +215,9 @@ func vtob(idx uint64, timestamp uint64) ([]byte, error) {
214215
// btov parses a byte array into an index and timestamp values.
215216
func btov(b []byte) (uint64, uint64, error) {
216217
var idx, timestamp uint64
218+
if l := len(b); l != 16 {
219+
return 0, 0, fmt.Errorf("input value is %d bytes long, expected %d", l, 16)
220+
}
217221
n, err := binary.Decode(b, binary.BigEndian, &idx)
218222
if err != nil {
219223
return 0, 0, fmt.Errorf("binary.Decode() could not decode idx: %v", err)

0 commit comments

Comments
 (0)