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 <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2019-07-30 17:11:27 -05:00
parent fd9ec22876
commit b2ec6dd1af
1 changed files with 13 additions and 2 deletions

View File

@ -29,6 +29,9 @@ import org.eclipse.jetty.util.IO;
*/ */
public class InputStreamRangeWriter implements RangeWriter public class InputStreamRangeWriter implements RangeWriter
{ {
public static final int NO_PROGRESS_LIMIT = 3;
public interface InputStreamSupplier public interface InputStreamSupplier
{ {
InputStream newInputStream() throws IOException; InputStream newInputStream() throws IOException;
@ -85,7 +88,7 @@ public class InputStreamRangeWriter implements RangeWriter
{ {
long skipSoFar = pos; long skipSoFar = pos;
long actualSkipped; long actualSkipped;
int noProgressLoopLimit = 3; int noProgressLoopLimit = NO_PROGRESS_LIMIT;
// loop till we reach desired point, break out on lack of progress. // loop till we reach desired point, break out on lack of progress.
while (noProgressLoopLimit > 0 && skipSoFar < skipTo) while (noProgressLoopLimit > 0 && skipSoFar < skipTo)
{ {
@ -94,9 +97,17 @@ public class InputStreamRangeWriter implements RangeWriter
{ {
noProgressLoopLimit--; noProgressLoopLimit--;
} }
else else if (actualSkipped > 0)
{ {
skipSoFar += actualSkipped; 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");
} }
} }