Issue #3840 - InputStream.skip() rules must be followed

+ break out if progress isn't made, loop if not enough
  progress is made

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2019-07-30 13:00:03 -05:00
parent 8601baa3cc
commit 5129f2c9ff
1 changed files with 22 additions and 1 deletions

View File

@ -83,7 +83,28 @@ public class InputStreamRangeWriter implements RangeWriter
}
if (pos < skipTo)
{
inputStream.skip(skipTo - pos);
long skipSoFar = pos;
long actualSkipped;
int noProgressLoopLimit = 3;
// loop till we reach desired point, break out on lack of progress.
while (noProgressLoopLimit > 0 && skipSoFar < skipTo)
{
actualSkipped = inputStream.skip(skipTo - skipSoFar);
if (actualSkipped == 0)
{
noProgressLoopLimit--;
}
else
{
skipSoFar += actualSkipped;
}
}
if (noProgressLoopLimit <= 0)
{
throw new IOException("No progress made to reach InputStream skip position " + (skipTo - pos));
}
pos = skipTo;
}