Co-authored-by: xiangbei.yzx <xiangbei.yzx@alibaba-inc.com>
pull/1087/head^2
zhixiangyuan 2020-08-10 23:04:47 +08:00 committed by GitHub
parent 3f2fefaf22
commit a318abcdc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -0,0 +1,18 @@
package run.halo.app.exception;
/**
* Image format exception.
*
* @author ZhiXiang Yuan
* @date 2020/08/10 02:11
*/
public class ImageFormatException extends BadRequestException {
public ImageFormatException(String message) {
super(message);
}
public ImageFormatException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -2,6 +2,7 @@ package run.halo.app.utils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.sf.image4j.codec.ico.ICODecoder; import net.sf.image4j.codec.ico.ICODecoder;
import run.halo.app.exception.ImageFormatException;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.imageio.ImageReader; import javax.imageio.ImageReader;
@ -24,7 +25,11 @@ public class ImageUtils {
log.debug("Current File type is : [{}]", extension); log.debug("Current File type is : [{}]", extension);
if (EXTENSION_ICO.equals(extension)) { if (EXTENSION_ICO.equals(extension)) {
return ICODecoder.read(is).get(0); try {
return ICODecoder.read(is).get(0);
} catch (IOException e) {
throw new ImageFormatException("ico 文件已损坏", e);
}
} else { } else {
return ImageIO.read(is); return ImageIO.read(is);
} }