Skip to content

Commit a4d16d9

Browse files
committed
Solved buffer overflow in case of a very large single line
The buffer printed would not get enlarged enough to fit the incomming buffer Fixes #2138
1 parent 982438c commit a4d16d9

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/org/rascalmpl/library/util/Monitor.rsc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,15 @@ test bool unfinishedLinesAtTheEndTest() {
225225
jobStep("job", "3", work=1);
226226
jobEnd("job");
227227
return true;
228+
}
229+
230+
// repo of issue #2138
231+
test bool printLongUnfinishedLine() {
232+
jobStart("job", totalWork=1);
233+
singleString = iprintToString(("" | it + "ab" | i <- [0..1000000])); // avoid concat tree printing in chunks
234+
println(singleString);
235+
jobStep("job", "prog", work=1);
236+
println("Done");
237+
jobEnd("job");
238+
return true;
228239
}

src/org/rascalmpl/repl/TerminalProgressBarMonitor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,10 @@ private void store(char[] newInput, int offset, int len) {
195195

196196
// first ensure capacity of the array
197197
if (curEnd + len >= curCapacity) {
198-
curCapacity *= 2;
198+
do {
199+
curCapacity *= 2;
200+
// increase size until it fits
201+
} while (curEnd + len >= curCapacity);
199202
buffer = Arrays.copyOf(buffer, curCapacity);
200203
}
201204

0 commit comments

Comments
 (0)