Skip to content

Bug (CSVReaderBase) - progress can be invalid for zero-length splits #3774

Description

@arthurianresolve

Issue

CSVReaderBase.getProgress() can return invalid progress when the split size is zero or the reader has not been initialized with a split size.

Problem

CSVReaderBase.getProgress() divides processedSize by totalSize without checking that totalSize is positive:

public long getTotalSize() {
return totalSize;
}

@Override
public float getProgress() {
    return Math.min(1f, (float) processedSize / (float) totalSize);
}

totalSize is set from the input split length:

} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
throw new IOException("Interrupted Exception thrown while attempting to get split length", ex);
}
}
/**

totalSize = genericSplit.getLength() * 4l;

If the split length is zero, or if getProgress() is called before initializeTotalSize(...), this divides by zero.

Expected behavior

Progress should stay in the valid range from 0.0f to 1.0f.

Actual behavior

Progress can become NaN when both processedSize and totalSize are zero, or 1.0f from positive infinity when processedSize is positive and totalSize is zero.

Affected readers

Classes that use or extend CSVReaderBase may be affected, including:

  • CSVRecordReader
  • NYCTLCReader

Suggested fix

Return 0.0f when totalSize <= 0. Otherwise, keep the existing capped progress calculation.

Test

Add focused coverage for CSVReaderBase.getProgress() with totalSize=0.

Expected result: progress returns 0.0f and is not NaN.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions