Skip to content

Commit 83342d5

Browse files
committed
store: fix ListMeta overflow check for negative Head
1 parent 2d99df4 commit 83342d5

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

store/list_helpers.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,10 @@ func marshalListMeta(meta ListMeta) ([]byte, error) {
5353
return nil, errors.WithStack(errors.Newf("list meta contains negative len: %d", meta.Len))
5454
}
5555
// Recompute Tail from Head+Len to guarantee the invariant and detect overflow.
56-
expectedTail := meta.Head + meta.Len
57-
if meta.Len > 0 && ((meta.Head > 0 && expectedTail < meta.Head) || (meta.Head < 0 && meta.Len > math.MaxInt64+meta.Head)) {
56+
if meta.Len > 0 && meta.Head > math.MaxInt64-meta.Len {
5857
return nil, errors.WithStack(errors.Newf("list meta Head+Len overflows int64: head=%d len=%d", meta.Head, meta.Len))
5958
}
60-
meta.Tail = expectedTail
59+
meta.Tail = meta.Head + meta.Len
6160

6261
buf := make([]byte, listMetaBinarySize)
6362
binary.BigEndian.PutUint64(buf[0:8], uint64(meta.Head)) //nolint:gosec // Head can be negative after LPUSH; uint64 cast preserves bits

0 commit comments

Comments
 (0)