mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
修复JSONUtil.parse()溢出问题
This commit is contained in:
@@ -5,6 +5,7 @@ import cn.hutool.core.comparator.PropertyComparator;
|
||||
import cn.hutool.core.exceptions.UtilException;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.Matcher;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.PageUtil;
|
||||
@@ -432,10 +433,8 @@ public class ListUtil {
|
||||
if (index < size) {
|
||||
list.set(index, element);
|
||||
} else {
|
||||
// issue#3286, 增加安全检查,最多增加2倍
|
||||
if(index > (list.size() + 1) * 2) {
|
||||
throw new UtilException("Index is too large:", index);
|
||||
}
|
||||
// issue#3286, 增加安全检查,最多增加10倍
|
||||
Validator.checkIndexLimit(index, list.size());
|
||||
for (int i = size; i < index; i++) {
|
||||
list.add(paddingElement);
|
||||
}
|
||||
|
@@ -1257,4 +1257,23 @@ public class Validator {
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查给定的index是否超出长度限制,默认检查超出倍数(10倍),此方法主要用于内部,检查包括:
|
||||
* <ul>
|
||||
* <li>数组调用setOrPadding时,最多允许padding的长度</li>
|
||||
* <li>List调用setOrPadding时,最多允许padding的长度</li>
|
||||
* <li>JSONArray调用setOrPadding时,最多允许padding的长度</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param index 索引
|
||||
* @param size 数组、列表长度
|
||||
* @since 5.8.22
|
||||
*/
|
||||
public static void checkIndexLimit(final int index, final int size) {
|
||||
// issue#3286, 增加安全检查,最多增加10倍
|
||||
if (index > (size + 1) * 10) {
|
||||
throw new ValidateException("Index [{}] is too large for size: [{}]", index, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user