From 31f61af71bec4e4b759eea98b68eaf586c64012f Mon Sep 17 00:00:00 2001 From: mguessan Date: Mon, 17 Mar 2014 23:11:30 +0000 Subject: [PATCH] From coverity: ImageIO.read may return null git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2260 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../davmail/exchange/dav/DavExchangeSession.java | 13 +++++++------ src/java/davmail/util/IOUtil.java | 3 +++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/java/davmail/exchange/dav/DavExchangeSession.java b/src/java/davmail/exchange/dav/DavExchangeSession.java index 92105aef..b5e34017 100644 --- a/src/java/davmail/exchange/dav/DavExchangeSession.java +++ b/src/java/davmail/exchange/dav/DavExchangeSession.java @@ -1237,14 +1237,15 @@ public class DavExchangeSession extends ExchangeSession { String contactPictureUrl = URIUtil.encodePath(getHref() + "/ContactPicture.jpg"); String photo = get("photo"); if (photo != null) { - // need to update photo - byte[] resizedImageBytes = IOUtil.resizeImage(IOUtil.decodeBase64(photo), 90); - final PutMethod putmethod = new PutMethod(contactPictureUrl); - putmethod.setRequestHeader("Overwrite", "t"); - putmethod.setRequestHeader("Content-Type", "image/jpeg"); - putmethod.setRequestEntity(new ByteArrayRequestEntity(resizedImageBytes, "image/jpeg")); try { + // need to update photo + byte[] resizedImageBytes = IOUtil.resizeImage(IOUtil.decodeBase64(photo), 90); + + putmethod.setRequestHeader("Overwrite", "t"); + putmethod.setRequestHeader("Content-Type", "image/jpeg"); + putmethod.setRequestEntity(new ByteArrayRequestEntity(resizedImageBytes, "image/jpeg")); + status = httpClient.executeMethod(putmethod); if (status != HttpStatus.SC_OK && status != HttpStatus.SC_CREATED) { throw new IOException("Unable to update contact picture: " + status + ' ' + putmethod.getStatusLine()); diff --git a/src/java/davmail/util/IOUtil.java b/src/java/davmail/util/IOUtil.java index 8526676d..f37380b0 100644 --- a/src/java/davmail/util/IOUtil.java +++ b/src/java/davmail/util/IOUtil.java @@ -124,6 +124,9 @@ public final class IOUtil { */ public static byte[] resizeImage(byte[] inputBytes, int max) throws IOException { BufferedImage inputImage = ImageIO.read(new ByteArrayInputStream(inputBytes)); + if (inputImage == null) { + throw new IOException("Unable to decode image data"); + } BufferedImage outputImage = resizeImage(inputImage, max); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(outputImage, "jpg", baos);