java.lang.ArithmeticException: / by zero, probably only for -Dthumbnailator.conserveMemoryWorkaround=true
See original GitHub issueExpected behavior
Thumbnail is generated without any exceptions.
Actual behavior
Lots of jpeg files (not all!) fail with the following exceptions:
java.lang.ArithmeticException: / by zero
at net.coobird.thumbnailator.tasks.io.InputStreamImageSource.readImage(Unknown Source) ~[thumbnailator-0.4.12.jar:0.4.12]
at net.coobird.thumbnailator.tasks.io.InputStreamImageSource.read(Unknown Source) ~[thumbnailator-0.4.12.jar:0.4.12]
at net.coobird.thumbnailator.tasks.io.FileImageSource.read(Unknown Source) ~[thumbnailator-0.4.12.jar:0.4.12]
at net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask.read(Unknown Source) ~[thumbnailator-0.4.12.jar:0.4.12]
at net.coobird.thumbnailator.Thumbnailator.createThumbnail(Unknown Source) ~[thumbnailator-0.4.12.jar:0.4.12]
at net.coobird.thumbnailator.Thumbnails$Builder.toFile(Unknown Source) ~[thumbnailator-0.4.12.jar:0.4.12]
Steps to reproduce the behavior
I ran into constant OOM on big files (namely the 6000*4000 jpeg), so I ran the import with -Dthumbnailator.conserveMemoryWorkaround=true
.
This prevents OOM, but big percentage of files fail with the aforementioned ArithmeticException.
Most probably these are big files that will otherwise fail with OOM.
The thumbnail generation code is:
public static void generateThumbnail(File imageFile, File thumbnailFile, Integer width) {
try {
// Make thumbnail
Thumbnails
.of(imageFile)
.width(width)
.outputFormat("jpg")
.toFile(thumbnailFile);
logger.debug("Thumbnail of image file {} generated to file {}", imageFile.getPath(), thumbnailFile.getPath());
}
catch (IOException e) {
logger.error(String.format("Error while generating thumbnail of file %s to thumbnail file %s", imageFile.getPath(), thumbnailFile.getPath()), e);
throw new RuntimeException(e);
}
}
Environment
-
OS vendor and version: Linux version 4.14.193-113.317.amzn1.x86_64 (mockbuild@koji-pdx-corp-builder-60005) (gcc version 7.2.1 20170915 (Red Hat 7.2.1-2) (GCC)) #1 SMP Thu Sep 3 19:08:08 UTC 2020
-
JDK vendor and version: openjdk version “11” 2018-09-25 OpenJDK Runtime Environment 18.9 (build 11+28) OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
-
Thumbnailator version: 0.4.12
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
Reproduced issue; happens when
.width
or.height
is called.Hope to have a fix out this weekend.
@dmitry-weirdo, thank you for reporting this.
There’s definitely some division happening, and I may have overlooked some possible division by zero situations. I can’t address this immediately, but I’ll try to follow-up on this as soon as I can.