mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
修复NumberUtil.toBigDecimal方法报StackOverflowError(CVE-2023-51080)
This commit is contained in:
parent
1aae080195
commit
4d6684e9ab
@ -2,7 +2,7 @@
|
|||||||
# 🚀Changelog
|
# 🚀Changelog
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.25(2024-01-09)
|
# 5.8.25(2024-01-11)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
* 【core 】 WatchServer新增通过Path获取WatchKey方法(pr#1145@Gitee)
|
* 【core 】 WatchServer新增通过Path获取WatchKey方法(pr#1145@Gitee)
|
||||||
@ -17,6 +17,7 @@
|
|||||||
* 【core 】 修复金额转换为英文时缺少 trillion 单位问题(pr#3454@Github)
|
* 【core 】 修复金额转换为英文时缺少 trillion 单位问题(pr#3454@Github)
|
||||||
* 【json 】 增加ParseConfig,通过增加maxNestingDepth参数避免StackOverflowError问题,修复CVE-2022-45688漏洞(issue#2748@Github)
|
* 【json 】 增加ParseConfig,通过增加maxNestingDepth参数避免StackOverflowError问题,修复CVE-2022-45688漏洞(issue#2748@Github)
|
||||||
* 【system】 修复UserInfo中用户名加/问题(pr#3458@Github)
|
* 【system】 修复UserInfo中用户名加/问题(pr#3458@Github)
|
||||||
|
* 【core 】 修复NumberUtil.toBigDecimal方法报StackOverflowError(CVE-2023-51080)(issue#3423@Github)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.24(2023-12-23)
|
# 5.8.24(2023-12-23)
|
||||||
|
@ -2153,8 +2153,8 @@ public class NumberUtil {
|
|||||||
if (number instanceof BigDecimal) {
|
if (number instanceof BigDecimal) {
|
||||||
return toStr((BigDecimal) number, isStripTrailingZeros);
|
return toStr((BigDecimal) number, isStripTrailingZeros);
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.isTrue(isValidNumber(number), "Number is non-finite!");
|
Assert.isTrue(isValidNumber(number), "Number is non-finite!");
|
||||||
|
|
||||||
// 去掉小数点儿后多余的0
|
// 去掉小数点儿后多余的0
|
||||||
String string = number.toString();
|
String string = number.toString();
|
||||||
if (isStripTrailingZeros) {
|
if (isStripTrailingZeros) {
|
||||||
@ -2212,6 +2212,8 @@ public class NumberUtil {
|
|||||||
if (null == number) {
|
if (null == number) {
|
||||||
return BigDecimal.ZERO;
|
return BigDecimal.ZERO;
|
||||||
}
|
}
|
||||||
|
// issue#3423@Github of CVE-2023-51080
|
||||||
|
Assert.isTrue(isValidNumber(number), "Number is invalid!");
|
||||||
|
|
||||||
if (number instanceof BigDecimal) {
|
if (number instanceof BigDecimal) {
|
||||||
return (BigDecimal) number;
|
return (BigDecimal) number;
|
||||||
@ -2247,7 +2249,8 @@ public class NumberUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 支持类似于 1,234.55 格式的数字
|
// 支持类似于 1,234.55 格式的数字
|
||||||
return toBigDecimal(parseNumber(numberStr));
|
final Number number = parseNumber(numberStr);
|
||||||
|
return toBigDecimal(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2269,6 +2272,7 @@ public class NumberUtil {
|
|||||||
return BigInteger.valueOf((Long) number);
|
return BigInteger.valueOf((Long) number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Assert.isTrue(isValidNumber(number), "Number is invalid!");
|
||||||
return toBigInteger(number.longValue());
|
return toBigInteger(number.longValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
package cn.hutool.core.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.Console;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.text.ParseException;
|
||||||
|
|
||||||
|
public class Issue3423Test {
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void toBigDecimalOfNaNTest() {
|
||||||
|
NumberUtil.toBigDecimal("NaN");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void toBigDecimalOfNaNTest2() throws ParseException {
|
||||||
|
final NumberFormat format = NumberFormat.getInstance();
|
||||||
|
((DecimalFormat) format).setParseBigDecimal(true);
|
||||||
|
final Number naN = format.parse("NaN");
|
||||||
|
Console.log(naN.getClass());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user