修复NumberUtil.toBigDecimal方法报StackOverflowError(CVE-2023-51080)

This commit is contained in:
Looly
2024-01-11 10:42:20 +08:00
parent 1aae080195
commit 4d6684e9ab
3 changed files with 32 additions and 3 deletions

View File

@@ -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());
}
}