Skip to content

Commit

Permalink
internal/metamorphic: overwrite unused bounds buffers
Browse files Browse the repository at this point in the history
After passing bounds to Pebble, overwrite the provided buffers with garbage.
This helps ensure we never accidentally retain user-provided bounds buffers
after a NewIter/SetOptions/SetBounds call.
  • Loading branch information
jbowens committed May 5, 2022
1 parent d35ca6b commit 42a7124
Showing 1 changed file with 57 additions and 13 deletions.
70 changes: 57 additions & 13 deletions internal/metamorphic/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bytes"
"fmt"
"io"
"math/rand"
"path/filepath"
"strings"

Expand Down Expand Up @@ -575,23 +576,37 @@ type newIterOp struct {

func (o *newIterOp) run(t *test, h *history) {
r := t.getReader(o.readerID)
var lower, upper []byte
if o.lower != nil {
lower = append(lower, o.lower...)
}
if o.upper != nil {
upper = append(upper, o.upper...)
}
opts := &pebble.IterOptions{
LowerBound: lower,
UpperBound: upper,
KeyTypes: pebble.IterKeyType(o.keyTypes),
RangeKeyMasking: pebble.RangeKeyMasking{
Suffix: o.rangeKeyMaskSuffix,
},
}
var i *pebble.Iterator
for {
i = r.NewIter(&pebble.IterOptions{
LowerBound: o.lower,
UpperBound: o.upper,
KeyTypes: pebble.IterKeyType(o.keyTypes),
RangeKeyMasking: pebble.RangeKeyMasking{
Suffix: o.rangeKeyMaskSuffix,
},
})
i = r.NewIter(opts)
if err := i.Error(); !errors.Is(err, errorfs.ErrInjected) {
break
}
// close this iter and retry NewIter
_ = i.Close()
}
t.setIter(o.iterID, i)

// Trash the bounds to ensure that Pebble doesn't rely on the stability of
// the user-provided bounds.
rand.Read(lower[:])
rand.Read(upper[:])

h.Recordf("%s // %v", o, i.Error())
}

Expand Down Expand Up @@ -629,7 +644,20 @@ type iterSetBoundsOp struct {

func (o *iterSetBoundsOp) run(t *test, h *history) {
i := t.getIter(o.iterID)
i.SetBounds(o.lower, o.upper)
var lower, upper []byte
if o.lower != nil {
lower = append(lower, o.lower...)
}
if o.upper != nil {
upper = append(upper, o.upper...)
}
i.SetBounds(lower, upper)

// Trash the bounds to ensure that Pebble doesn't rely on the stability of
// the user-provided bounds.
rand.Read(lower[:])
rand.Read(upper[:])

h.Recordf("%s // %v", o, i.Error())
}

Expand All @@ -651,14 +679,30 @@ type iterSetOptionsOp struct {

func (o *iterSetOptionsOp) run(t *test, h *history) {
i := t.getIter(o.iterID)
i.SetOptions(&pebble.IterOptions{
LowerBound: o.lower,
UpperBound: o.upper,

var lower, upper []byte
if o.lower != nil {
lower = append(lower, o.lower...)
}
if o.upper != nil {
upper = append(upper, o.upper...)
}
opts := &pebble.IterOptions{
LowerBound: lower,
UpperBound: upper,
KeyTypes: pebble.IterKeyType(o.keyTypes),
RangeKeyMasking: pebble.RangeKeyMasking{
Suffix: o.rangeKeyMaskSuffix,
},
})
}

i.SetOptions(opts)

// Trash the bounds to ensure that Pebble doesn't rely on the stability of
// the user-provided bounds.
rand.Read(lower[:])
rand.Read(upper[:])

h.Recordf("%s // %v", o, i.Error())
}

Expand Down

0 comments on commit 42a7124

Please sign in to comment.