Skip to content

Commit

Permalink
Merge pull request #55 from redpanda-data/nv/do-not-crash-no-header
Browse files Browse the repository at this point in the history
verifier: do not crash with index out of range for invalid data
  • Loading branch information
nvartolomei authored Oct 13, 2024
2 parents e100d9f + 2007a3a commit a4dff21
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/worker/verifier/validator_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,22 @@ type ValidatorStatus struct {
}

func (cs *ValidatorStatus) ValidateRecord(r *kgo.Record, validRanges *TopicOffsetRanges) {
expect_header_key := fmt.Sprintf("%06d.%018d", 0, r.Offset)
expect_header_value := fmt.Sprintf("%06d.%018d", 0, r.Offset)
log.Debugf("Consumed %s on p=%d at o=%d", r.Key, r.Partition, r.Offset)
cs.lock.Lock()
defer cs.lock.Unlock()

if expect_header_key != string(r.Headers[0].Value) {
var got_header_value string
if len(r.Headers) > 0 {
got_header_value = string(r.Headers[0].Value)
}

if expect_header_value != got_header_value {
shouldBeValid := validRanges.Contains(r.Partition, r.Offset)

if shouldBeValid {
cs.InvalidReads += 1
util.Die("Bad read at offset %d on partition %s/%d. Expect '%s', found '%s'", r.Offset, r.Topic, r.Partition, expect_header_key, r.Headers[0].Value)
util.Die("Bad read at offset %d on partition %s/%d. Expect '%s', found '%s'", r.Offset, r.Topic, r.Partition, expect_header_value, got_header_value)
} else {
cs.OutOfScopeInvalidReads += 1
log.Infof("Ignoring read validation at offset outside valid range %s/%d %d", r.Topic, r.Partition, r.Offset)
Expand Down

0 comments on commit a4dff21

Please sign in to comment.