From e1e416608c2ed864cb7d93fc582dd267aa5a0b5e Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 1 Mar 2019 10:08:00 +0300 Subject: ImageUtils catch IOException from apache-imaging --- src/main/java/com/juick/server/util/ImageUtils.java | 2 +- src/test/java/com/juick/server/tests/ServerTests.java | 9 +++++++++ src/test/resources/2936611-57.jpg | Bin 0 -> 101818 bytes 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/2936611-57.jpg diff --git a/src/main/java/com/juick/server/util/ImageUtils.java b/src/main/java/com/juick/server/util/ImageUtils.java index d16faf8f..2f5d3292 100644 --- a/src/main/java/com/juick/server/util/ImageUtils.java +++ b/src/main/java/com/juick/server/util/ImageUtils.java @@ -108,7 +108,7 @@ public class ImageUtils { } } } - } catch (ImageReadException e) { + } catch (ImageReadException | IOException e) { // failed to read metadata. // nothing to do here, return image as is. } diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java index c8f07d06..a0d10988 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -215,6 +215,8 @@ public class ServerTests { private Resource hubzillaFollow; @Value("classpath:announce.json") private Resource noteWithDocument; + @Value("classpath:2936611-57.jpg") + private Resource jpegNoJfifTiff; @Inject private KeystoreManager testKeystoreManager; @@ -1177,6 +1179,13 @@ public class ServerTests { assertThat(postJpgiPhone.getNewMessage().get().getAttachment().getHeight(), is(1280)); assertThat(postJpgiPhone.getNewMessage().get().getAttachment().getMedium().getHeight(), is(1024)); assertThat(postJpgiPhone.getNewMessage().get().getAttachment().getSmall().getHeight(), is(512)); + CommandResult postNojfifTiff = commandsManager.processCommand(ugnich, "YO2", jpegNoJfifTiff.getURI()); + assertThat(postNojfifTiff.getNewMessage().isPresent(), is(true)); + int mid2 = postNojfifTiff.getNewMessage().get().getMid(); + File originalFile2 = Paths.get(imgDir, "p", String.format("%d.jpg", mid2)).toFile(); + assertThat(originalFile2.exists(), is(true)); + File mediumFile2 = Paths.get(imgDir, "photos-1024", String.format("%d.jpg", mid2)).toFile(); + assertThat(mediumFile2.exists(), is(true)); } @Test public void changeExtensionWhenReceiveFileWithWrongContentType() throws Exception { diff --git a/src/test/resources/2936611-57.jpg b/src/test/resources/2936611-57.jpg new file mode 100644 index 00000000..af4f9c91 Binary files /dev/null and b/src/test/resources/2936611-57.jpg differ -- cgit v1.2.3