mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2024-11-26 20:16:18 +01:00
Fix potential infinity exploit.
This commit is contained in:
parent
f9b53695d6
commit
230d50d81b
@ -36,6 +36,10 @@ public class NumberUtils {
|
|||||||
return INVALID_DOUBLE;
|
return INVALID_DOUBLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Double.isInfinite(doub) || Double.isNaN(doub)) {
|
||||||
|
return INVALID_DOUBLE;
|
||||||
|
}
|
||||||
|
|
||||||
return doub;
|
return doub;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,12 +16,14 @@ public class NumberUtilsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testParsePositive() {
|
public void testParsePositive() {
|
||||||
// Valid input
|
// Valid input
|
||||||
Assert.assertEquals(NumberUtils.parsePositiveDouble("69.0"), 69.0, 0.0);
|
Assert.assertEquals(69.0, NumberUtils.parsePositiveDouble("69.0"), 0.0);
|
||||||
// Valid but not positive
|
// Valid but not positive
|
||||||
Assert.assertEquals(NumberUtils.parsePositiveDouble("-10.0"), -1.0, 0.0);
|
Assert.assertEquals(-1.0, NumberUtils.parsePositiveDouble("-10.0"), 0.0);
|
||||||
// Invalid
|
// Invalid
|
||||||
Assert.assertEquals(NumberUtils.parsePositiveDouble("nan"), -1.0, 0.0);
|
Assert.assertEquals(-1.0, NumberUtils.parsePositiveDouble("nan"), 0.0);
|
||||||
Assert.assertEquals(NumberUtils.parsePositiveDouble("ponies"), -1.0, 0.0);
|
Assert.assertEquals(-1.0, NumberUtils.parsePositiveDouble("ponies"), 0.0);
|
||||||
|
// Infinite
|
||||||
|
Assert.assertEquals(-1.0, NumberUtils.parsePositiveDouble("1E1000000000"), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user