You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 18, 2024. It is now read-only.
Repository navigation
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
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:
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.
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.
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.
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 ?
Activity
mordechaim commentedon Sep 6, 2020
Thanks, I'll look into this.
Does this happen on JDK 11+ too?
yildiz-online commentedon Sep 6, 2020
Sorry forgot to mention env,
java 11, win64
mordechaim commentedon Sep 6, 2020
The env usually doesn't matter but in the case of
String::repeatI 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.
mordechaim commentedon Sep 6, 2020
I have a hunch is an int overflow bug.
mordechaim commentedon Sep 7, 2020
The problem is here:
update4j/src/main/java/org/update4j/ConfigImpl.java
Line 354 in 2c4c04c
Which is a divide by zero. While for integers is fails with an
ArithmeticExceptionit will silently pass for real numbers with valueFloat.POSITIVE_INFINITY.Then in this line:
update4j/src/main/java/org/update4j/service/DefaultUpdateHandler.java
Lines 188 to 189 in 2c4c04c
we multiple an int by Infinity which results in
Integer.MAX_VALUE.Attempting to repeat a string by max value will cause an
OutOfMemoryErrormordechaim commentedon Sep 7, 2020
I think this a very special case that should probably not be handled by update4j. It will fail regardless in the file validation phase.
yildiz-online commentedon Sep 8, 2020
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 ?
mordechaim commentedon Sep 8, 2020
The safest and least intrusive would be to simply clamp the progress between 0 and 1 and never allow leaking out of those bounds.
Clamp progress value between 0 and 1. Resolve update4j#106