Skip to content

Commit fca97cd

Browse files
committed
[CSV-311] OutOfMemory for very long rows despite using column value of
type Reader
1 parent 699b858 commit fca97cd

2 files changed

Lines changed: 3 additions & 17 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<action type="fix" dev="ggregory" due-to="step-security-bot">[StepSecurity] CI: Harden GitHub Actions #329, #330.</action>
5151
<action type="fix" issue="CSV-147" dev="ggregory" due-to="Steven Peterson, Benedikt Ritter, Gary Gregory, Joerg Schaible, Buddhi De Silva, Elliotte Rusty Harold">Better error message during faulty CSV record read #347.</action>
5252
<action type="fix" issue="CSV-310" dev="ggregory" due-to="Buddhi De Silva">Misleading error message when QuoteMode set to None #352.</action>
53+
<action type="fix" issue="CSV-311" dev="ggregory" due-to="Christian Feuersaenger, Gary Gregory">OutOfMemory for very long rows despite using column value of type Reader.</action>
5354
<!-- UPDATE -->
5455
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump commons-io:commons-io: from 2.11.0 to 2.15.1.</action>
5556
<action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump commons-parent from 57 to 67.</action>

src/main/java/org/apache/commons/csv/CSVFormat.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2325,28 +2325,13 @@ private void printWithQuotes(final Reader reader, final Appendable appendable) t
23252325
final char quote = getQuoteCharacter().charValue();
23262326
// (1) Append opening quote
23272327
append(quote, appendable);
2328-
// (2) Append Reader content
2329-
final StringBuilder builder = new StringBuilder(IOUtils.DEFAULT_BUFFER_SIZE);
2328+
// (2) Append Reader contents, doubling quotes
23302329
int c;
2331-
int pos = 0;
23322330
while (EOF != (c = reader.read())) {
2333-
builder.append((char) c);
2331+
append((char) c, appendable);
23342332
if (c == quote) {
2335-
// Append current segment
2336-
if (pos > 0) {
2337-
append(builder.toString(), appendable);
2338-
// Recycle builder
2339-
builder.setLength(0);
2340-
pos = -1;
2341-
}
2342-
// Append nested quote
23432333
append(quote, appendable);
23442334
}
2345-
pos++;
2346-
}
2347-
// Append last segment
2348-
if (pos > 0) {
2349-
append(builder.substring(0, pos), appendable);
23502335
}
23512336
// (3) Append closing quote
23522337
append(quote, appendable);

0 commit comments

Comments
 (0)