Skip to content

Commit

Permalink
make sure processor doesn't return more records
Browse files Browse the repository at this point in the history
  • Loading branch information
lovromazgon committed Mar 7, 2024
1 parent 8f11708 commit 909508e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/processor/runnable_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func (p *RunnableProcessor) Process(ctx context.Context, records []opencdc.Recor

if len(keptRecords) > 0 {
outRecs = p.proc.Process(ctx, keptRecords)
if len(outRecs) > len(keptRecords) {
return []sdk.ProcessedRecord{
sdk.ErrorRecord{Error: cerrors.New("processor returned more records than input")},
}
}
}
if err != nil {
outRecs = append(outRecs, sdk.ErrorRecord{Error: err})
Expand All @@ -111,6 +116,8 @@ func (p *RunnableProcessor) Process(ctx context.Context, records []opencdc.Recor
tmp := make([]sdk.ProcessedRecord, len(outRecs)+len(passthroughRecordIndexes))
prevIndex := -1
for i, index := range passthroughRecordIndexes {
// TODO index-i can be out of bounds if the processor returns
// fewer records than the input.
copy(tmp[prevIndex+1:index], outRecs[prevIndex-i+1:index-i])
tmp[index] = sdk.SingleRecord(records[index])
prevIndex = index
Expand Down

0 comments on commit 909508e

Please sign in to comment.