aboutsummaryrefslogtreecommitdiff
path: root/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java')
-rw-r--r--src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java
index 5c93d89e0e..8f58f5b3e6 100644
--- a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java
+++ b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -374,7 +374,10 @@ public class JPEGImageReader extends ImageReader {
// And set current image since we've read it now
currentImage = 0;
}
- if (seekForwardOnly) {
+ // If the image positions list is empty as in the case of a tables-only
+ // stream, then attempting to access the element at index
+ // imagePositions.size() - 1 will cause an IndexOutOfBoundsException.
+ if (seekForwardOnly && !imagePositions.isEmpty()) {
Long pos = (Long) imagePositions.get(imagePositions.size()-1);
iis.flushBefore(pos.longValue());
}
@@ -491,6 +494,11 @@ public class JPEGImageReader extends ImageReader {
if (!tablesOnlyChecked) {
checkTablesOnly();
}
+ // If the image positions list is empty as in the case of a tables-only
+ // stream, then no image data can be read.
+ if (imagePositions.isEmpty()) {
+ throw new IIOException("No image data present to read");
+ }
if (imageIndex < imagePositions.size()) {
iis.seek(((Long)(imagePositions.get(imageIndex))).longValue());
} else {