提交 ebc2b31d 编写于 作者: V Vlad Ilyushchenko

bugfix: Numbers.parseInt() could overflow without throwing exception

上级 c93a85e1
......@@ -1451,6 +1451,9 @@ public final class Numbers {
throw NumericException.INSTANCE;
}
// val * 10 + (c - '0')
if (val < (Integer.MIN_VALUE / 10)) {
throw NumericException.INSTANCE;
}
int r = (val << 3) + (val << 1) - (c - '0');
if (r > val) {
throw NumericException.INSTANCE;
......
......@@ -1620,7 +1620,7 @@ public class SqlCodeGeneratorTest extends AbstractGriffinTest {
public void testLatestByMissingKeyValuesIndexedFiltered() throws Exception {
TestMatchFunctionFactory.clear();
assertQuery("a\tb\tk\n" +
"54.551753247857\tHYRX\t1970-01-05T13:16:48.248832Z\n",
"54.551753247857\tHYRX\t1970-02-02T07:00:00.000000Z\n",
"select * from x latest by b where b in ('XYZ', 'HYRX') and a > 30 and test_match()",
"create table x as " +
"(" +
......@@ -1640,7 +1640,7 @@ public class SqlCodeGeneratorTest extends AbstractGriffinTest {
" from long_sequence(1)" +
") timestamp(t)",
"a\tb\tk\n" +
"54.551753247857\tHYRX\t1970-01-05T13:16:48.248832Z\n" +
"54.551753247857\tHYRX\t1970-02-02T07:00:00.000000Z\n" +
"88.100000000000\tXYZ\t1971-01-01T00:00:00.000000Z\n");
// good
......
......@@ -360,6 +360,11 @@ public class NumbersTest {
Numbers.parseInt("2147483648");
}
@Test(expected = NumericException.class)
public void testParseIntOverflow3() throws Exception {
Numbers.parseInt("5000000000");
}
@Test(expected = NumericException.class)
public void testParseIntSignOnly() throws Exception {
Numbers.parseInt("-");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册