Skip to content

Commit 0293799

Browse files
committed
Defend against hypothetical negative array sizes.
1 parent be9be0c commit 0293799

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/main/java/org/jenkinsci/plugins/workflow/log/FileLogStorage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ private final class IndexOutputStream extends OutputStream {
268268
if (space != -1 && line.substring(space + 1).equals(id)) {
269269
pos = lastTransition;
270270
}
271-
} else {
271+
} else if (lastTransition > pos) {
272272
raf.seek(pos);
273273
if (lastTransition > pos + Integer.MAX_VALUE) {
274274
throw new IOException("Cannot read more than 2Gib at a time"); // ByteBuffer does not support it anyway
@@ -287,9 +287,9 @@ private final class IndexOutputStream extends OutputStream {
287287
raf.readFully(data);
288288
buf.write(data);
289289
pos = -1;
290-
}
290+
} // else some sort of mismatch
291291
}
292-
if (pos != -1) {
292+
if (pos != -1 && /* otherwise race condition? */ end > pos) {
293293
// In case the build is ongoing and we are still actively writing content for this step,
294294
// we will hit EOF before any other transition. Otherwise identical to normal case above.
295295
raf.seek(pos);

0 commit comments

Comments
 (0)