[OpenJDK 2D-Dev] RFR: JDK-8263362: Avoid division by 0 in java/awt/font/TextJustifier.java justify
Matthias Baesken
mbaesken at openjdk.java.net
Wed Mar 10 12:58:08 UTC 2021
On Wed, 10 Mar 2021 12:41:05 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:
>> In java/awt/font/TextJustifier.java justify-method there is a potential code path where divison by zero might happen , see also the Sonar finding
>> https://sonarcloud.io/project/issues?id=shipilev_jdk&open=AXcqMwpm8sPJZZzONu1k&resolved=false&severities=CRITICAL&types=BUG
>>
>>
>> boolean hitLimit = (weight == 0) || (!lastPass && ((delta < 0) == (delta < gslimit)));
>> boolean absorbing = hitLimit && absorbweight > 0;
>> // predivide delta by weight
>> float weightedDelta = delta / weight; // not used if weight == 0
>>
>> In case of (weight == 0) the division should not be done because the value of weightedDelta is unused in this case anyway.
>
> src/java.desktop/share/classes/java/awt/font/TextJustifier.java line 159:
>
>> 157: // predivide delta by weight
>> 158: float weightedDelta = 0;
>> 159: if (weight != 0) { // not used if weight == 0
>
> Can it ever be -ve? Maybe we can do weight > 0 check just as we do for absorbweight?
Hi, I am not sure about the weight > 0 check ; weight is initialized with 0: weight = 0; and later some values are potentially added up to weight: weight += gi.weight;
I am not sure about those gi.weight values, maybe they can be negative too ?
-------------
PR: https://git.openjdk.java.net/jdk/pull/2912
More information about the 2d-dev
mailing list