#843: Correctly handle empty image resources section.

This commit is contained in:
Harald Kuhr 2023-10-20 12:26:36 +02:00
parent 4d3f691e6a
commit 9720a931c5

View File

@ -864,10 +864,15 @@ public final class PSDImageReader extends ImageReaderBase {
long imageResourcesLength = imageInput.readUnsignedInt();
if (pParseData && metadata.imageResources == null && imageResourcesLength > 0) {
long expectedEnd = imageInput.getStreamPosition() + imageResourcesLength;
if (pParseData && metadata.imageResources == null) {
if (imageResourcesLength == 0) {
metadata.imageResources = Collections.emptyList();
}
else {
metadata.imageResources = new ArrayList<>();
long expectedEnd = imageInput.getStreamPosition() + imageResourcesLength;
while (imageInput.getStreamPosition() < expectedEnd) {
PSDImageResource resource = PSDImageResource.read(imageInput);
metadata.imageResources.add(resource);
@ -881,6 +886,7 @@ public final class PSDImageReader extends ImageReaderBase {
throw new IIOException("Corrupt PSD document"); // ..or maybe just a bug in the reader.. ;-)
}
}
}
// TODO: We should now be able to flush input
// imageInput.flushBefore(metadata.imageResourcesStart + imageResourcesLength + 4);