From b2ec6dd1af54e607d32518749df840bf3d4ece23 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 30 Jul 2019 17:11:27 -0500 Subject: [PATCH] Issue #3840 - Fixing for InputStream.skip() behaviors + Reset progress on any positive skip value + Throw IOException(EOF) for any negative skip value Signed-off-by: Joakim Erdfelt --- .../server/resource/InputStreamRangeWriter.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/resource/InputStreamRangeWriter.java b/jetty-server/src/main/java/org/eclipse/jetty/server/resource/InputStreamRangeWriter.java index e3b0d030960..d2bc2eaf8c9 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/resource/InputStreamRangeWriter.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/resource/InputStreamRangeWriter.java @@ -29,6 +29,9 @@ import org.eclipse.jetty.util.IO; */ public class InputStreamRangeWriter implements RangeWriter { + + public static final int NO_PROGRESS_LIMIT = 3; + public interface InputStreamSupplier { InputStream newInputStream() throws IOException; @@ -85,7 +88,7 @@ public class InputStreamRangeWriter implements RangeWriter { long skipSoFar = pos; long actualSkipped; - int noProgressLoopLimit = 3; + int noProgressLoopLimit = NO_PROGRESS_LIMIT; // loop till we reach desired point, break out on lack of progress. while (noProgressLoopLimit > 0 && skipSoFar < skipTo) { @@ -94,9 +97,17 @@ public class InputStreamRangeWriter implements RangeWriter { noProgressLoopLimit--; } - else + else if (actualSkipped > 0) { skipSoFar += actualSkipped; + noProgressLoopLimit = NO_PROGRESS_LIMIT; + } + else + { + // negative values means the stream was closed or reached EOF + // either way, we've hit a state where we can no longer + // fulfill the requested range write. + throw new IOException("EOF reached before InputStream skip destination"); } }