Skip to content

Commit

Permalink
#843: Correctly handle empty image resources section.
Browse files Browse the repository at this point in the history
  • Loading branch information
haraldk committed Oct 20, 2023
1 parent 4d3f691 commit 9720a93
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -864,21 +864,27 @@ private void readImageResources(final boolean pParseData) throws IOException {

long imageResourcesLength = imageInput.readUnsignedInt();

if (pParseData && metadata.imageResources == null && imageResourcesLength > 0) {
long expectedEnd = imageInput.getStreamPosition() + imageResourcesLength;
metadata.imageResources = new ArrayList<>();

while (imageInput.getStreamPosition() < expectedEnd) {
PSDImageResource resource = PSDImageResource.read(imageInput);
metadata.imageResources.add(resource);
if (pParseData && metadata.imageResources == null) {
if (imageResourcesLength == 0) {
metadata.imageResources = Collections.emptyList();
}
else {
metadata.imageResources = new ArrayList<>();

if (DEBUG) {
System.out.println("imageResources: " + metadata.imageResources);
}
long expectedEnd = imageInput.getStreamPosition() + imageResourcesLength;

while (imageInput.getStreamPosition() < expectedEnd) {
PSDImageResource resource = PSDImageResource.read(imageInput);
metadata.imageResources.add(resource);
}

if (DEBUG) {
System.out.println("imageResources: " + metadata.imageResources);
}

if (imageInput.getStreamPosition() != expectedEnd) {
throw new IIOException("Corrupt PSD document"); // ..or maybe just a bug in the reader.. ;-)
if (imageInput.getStreamPosition() != expectedEnd) {
throw new IIOException("Corrupt PSD document"); // ..or maybe just a bug in the reader.. ;-)
}
}
}

Expand Down

0 comments on commit 9720a93

Please sign in to comment.