Skip to content

Commit

Permalink
#55 - Handle JPEGs where APP0 marker is not the first in JFIF metadat…
Browse files Browse the repository at this point in the history
…a. JDK fails reading such files even if image body is fine. Check https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6488904
  • Loading branch information
Samir Vaidya committed Sep 25, 2022
1 parent 9c86c50 commit 516941c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/com/openstego/desktop/util/ImageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,14 @@ private static ImageHolder readImage(InputStream is) throws OpenStegoException {
ImageReader reader = readers.next();
reader.setInput(imageIS);
BufferedImage image = reader.read(0);
IIOMetadata metadata = reader.getImageMetadata(0);
IIOMetadata metadata;
try {
metadata = reader.getImageMetadata(0);
} catch (IOException e) {
ImageWriter writer = ImageIO.getImageWriter(reader);
ImageWriteParam param = writer.getDefaultWriteParam();
metadata = writer.getDefaultImageMetadata(ImageTypeSpecifier.createFromRenderedImage(image), param);
}
return new ImageHolder(image, metadata);
} catch (IOException e) {
throw new OpenStegoException(e);
Expand Down

0 comments on commit 516941c

Please sign in to comment.