Skip to content
This repository was archived by the owner on Mar 18, 2024. It is now read-only.
This repository was archived by the owner on Mar 18, 2024. It is now read-only.

DefaultUpdateHandler heap space exception when file to download is 0b #106

Closed

Description

@yildiz-online

Due to a bug in my app, the update4j xml generated ended up with a 0b file size instead of correct size(65mo), leading to this exception in the client using that xml:

Part of the XML file:

file uri="http://files.yildiz-games.be/play50hz/player/retro-player.jar" path="${user.dir}/lib/retro-player.jar" size="0" checksum="1"

Exception:

Downloading 0 B 0% [> ] Exception in thread "Progress Printer" java.lang.OutOfMemoryError: Java heap space
at java.base/java.util.Arrays.copyOf(Unknown Source)
at java.base/java.util.StringJoiner.add(Unknown Source)
at java.base/java.lang.String.join(Unknown Source)
at org.update4j.util.StringUtils.repeat(StringUtils.java:123)
at org.update4j.service.DefaultUpdateHandler.renderProgress(DefaultUpdateHandler.java:189)
at org.update4j.service.DefaultUpdateHandler$1.run(DefaultUpdateHandler.java:127)
at java.base/java.util.TimerThread.mainLoop(Unknown Source)
at java.base/java.util.TimerThread.run(Unknown Source)

Same file with expected size(65mo) is handled correctly.

Activity

  1. mordechaim commented on Sep 6, 2020

    @mordechaim
    Contributor

    Thanks, I'll look into this.

    Does this happen on JDK 11+ too?

  2. yildiz-online commented on Sep 6, 2020

    @yildiz-online
    Author

    Sorry forgot to mention env,
    java 11, win64

  3. mordechaim commented on Sep 6, 2020

    @mordechaim
    Contributor

    Sorry forgot to mention env,
    java 11, win64

    The env usually doesn't matter but in the case of String::repeat I created a polyfill to work on earlier versions. It seems to be a bug in the core JDK.

    I'll look into it when I have a chance.

  4. mordechaim commented on Sep 6, 2020

    @mordechaim
    Contributor

    I have a hunch is an int overflow bug.

  5. mordechaim commented on Sep 7, 2020

    @mordechaim
    Contributor

    The problem is here:

    handler.updateDownloadFileProgress(file, (float) (currentCompleted / file.getSize()));

    Which is a divide by zero. While for integers is fails with an ArithmeticException it will silently pass for real numbers with value Float.POSITIVE_INFINITY.

    Then in this line:

    int pieces = (int) ((progressWidth - 2) * currentFrac);
    String line = repeat(pieces, "=");

    we multiple an int by Infinity which results in Integer.MAX_VALUE.

    Attempting to repeat a string by max value will cause an OutOfMemoryError

  6. mordechaim commented on Sep 7, 2020

    @mordechaim
    Contributor

    I think this a very special case that should probably not be handled by update4j. It will fail regardless in the file validation phase.

  7. yildiz-online commented on Sep 8, 2020

    @yildiz-online
    Author

    Totally agree that it should fail (input is wrong anyway) but would be nice to have a better suited exception thrown early to avoid filling the heap space .

    Or maybe ignore files with size 0 and checksum 1 ?

  8. mordechaim commented on Sep 8, 2020

    @mordechaim
    Contributor

    The safest and least intrusive would be to simply clamp the progress between 0 and 1 and never allow leaking out of those bounds.

  9. added a commit that references this issue on Oct 7, 2025
    c774829
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions