TMI-119: Fixed endless loop, trying to read 0 bytes at EOF caused by bogus segment lengths...

This commit is contained in:
Harald Kuhr
2015-03-19 21:30:37 +01:00
parent 4839c61f5c
commit 11f33741d4
3 changed files with 17 additions and 2 deletions
@@ -271,7 +271,8 @@ final class JPEGSegmentImageInputStream extends ImageInputStreamImpl {
while (total < len) {
repositionAsNecessary();
int count = stream.read(b, off + total, (int) Math.min(len - total, segment.end() - streamPos));
long bytesLeft = segment.end() - streamPos; // If no more bytes after reposition, we're at EOF
int count = bytesLeft == 0 ? -1 : stream.read(b, off + total, (int) Math.min(len - total, bytesLeft));
if (count == -1) {
// EOF