mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
修复SONArray的add()方法抛出OutOfMemory异常问题
This commit is contained in:
parent
45e9006a94
commit
9ba8f9ca5d
@ -25,7 +25,8 @@
|
||||
* 【core 】 修复Ipv4Util.getEndIpLong 取反符号导致数据越界(issue#I7U1OQ@Gitee)
|
||||
* 【http 】 修复302重定向时,Location中的问号被转义问题(issue#3265@Github)
|
||||
* 【core 】 修复CombinationAnnotationElement判断循环问题(pr#3267@Github)
|
||||
* 【core 】 修复StrUtil#containsAny NPE问题问题(pr#1063@Gitee)
|
||||
* 【core 】 修复StrUtil#containsAny NPE问题(pr#1063@Gitee)
|
||||
* 【all 】 修复SONArray的add()方法抛出OutOfMemory异常问题(issue#3286@Github)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.21(2023-07-29)
|
||||
|
@ -2,6 +2,7 @@ package cn.hutool.core.collection;
|
||||
|
||||
import cn.hutool.core.comparator.PinyinComparator;
|
||||
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.util.ArrayUtil;
|
||||
@ -431,6 +432,10 @@ 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);
|
||||
}
|
||||
for (int i = size; i < index; i++) {
|
||||
list.add(paddingElement);
|
||||
}
|
||||
|
@ -457,6 +457,10 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
InternalJSONUtil.testValidity(element);
|
||||
this.rawList.add(index, JSONUtil.wrap(element, this.config));
|
||||
} else {
|
||||
// issue#3286, 增加安全检查,最多增加2倍
|
||||
if(index > (this.size() + 1) * 2) {
|
||||
throw new JSONException("Index is too large:", index);
|
||||
}
|
||||
while (index != this.size()) {
|
||||
this.add(JSONNull.NULL);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user