question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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)) #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:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
coobirdcommented, Oct 14, 2020

Reproduced issue; happens when .width or .height is called.

Hope to have a fix out this weekend.

1reaction
coobirdcommented, Sep 29, 2020

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found