Skip to content

Commit

Permalink
carlog repair: More fuzzing, reenable repair
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Nov 17, 2023
1 parent b34d296 commit a37cad4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
3 changes: 1 addition & 2 deletions rbdeal/deal_repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,9 @@ func (r *ribs) fetchGroupHttp(ctx context.Context, workerID int, group ribs2.Gro
log.Errorw("failed to create repair reader", "err", err, "group", group, "provider", candidate.Provider, "url", reqUrl.String())
continue
}
_ = repairReader // disable for now, it's a whee bit broken

cc := new(ributil.DataCidWriter)
commdReader := io.TeeReader(robustReqReader, cc)
commdReader := io.TeeReader(repairReader, cc)

_, err = io.Copy(f, commdReader)
done()
Expand Down
26 changes: 26 additions & 0 deletions ributil/repair_car_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,29 @@ func FuzzRepairCarLog1c(f *testing.F) {
fuzzWithRealData(t, root, bs, data, coffs, corruptCallback)
})
}

func FuzzRepairCarLog3c(f *testing.F) {
data, root, bs := prepareCarlogTestData(f)

f.Add(int(0), byte(0), int(0), byte(0), int(0), byte(0))
f.Fuzz(func(t *testing.T, c0 int, b0 byte, c1 int, b1 byte, c2 int, b2 byte) {
corruptOffset := []int{(c0 << 8) | int(b0), (c1 << 8) | int(b1), (c2 << 8) | int(b2)}

corruptCallback := func(b byte, ci int) byte {
// Example corruption function, replace with actual logic
return b ^ byte(corruptOffset[ci]&0xff)
}

coffs := lo.Map(corruptOffset, func(v int, i int) int {
co := v & 0x7fffffff
co >>= 8
co = co % len(testCar)
if co == 0 {
co = 1 // don't corrupt first byte, too we won't bother with handling that
}
return co
})

fuzzWithRealData(t, root, bs, data, coffs, corruptCallback)
})
}

0 comments on commit a37cad4

Please sign in to comment.