Skip to content

java.lang.ArithmeticException: / by zero, probably only for -Dthumbnailator.conserveMemoryWorkaround=true #161

@dmitry-weirdo

Description

@dmitry-weirdo

Expected 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)) Handle large image files in an memory-efficient manner #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

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions