[BUG] OutOfMemoryError in JSON.parseArray
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
以下代码使用fastjson2和fastjson 1.2.83会抛出异常,使用fastjson 2.0.50 会导致内存溢出。
### 环境信息
- OS信息: [MacOS 12.7.4 M1 Pro 16 GB]
- JDK信息: [Openjdk 17.0.6]
- 版本信息:[Fastjson 2.0.50]
### 重现步骤
```java
import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Test;
import java.util.List;
public class Issue1184Mutated_547 {
@Test
public void test() {
final String source = "[{\"code\":\"face_1\",\"disc\":\"人脸\"}]";
List devices = JSON.parseArray(source, VerifyDevice.class);
}
@Test
public void test_fj() {
final String source = "[{\"code\":\"face_1\",\"disc\":\"人脸\"}]";
List devices = com.alibaba.fastjson.JSON.parseArray(source, VerifyDevice.class);
}
public enum VerifyDevice {
FACE_DETECT("face_1", "人脸"),
IC_CARD("ic_2", "IC卡");
private final String code;
private final String disc;
VerifyDevice(String code, String disc) {
this.code = code;
this.disc = disc;
}
public String getCode() {
return code;
}
public String getDisc() {
return disc;
}
}
}
```
### 相关日志输出
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.base/java.util.Arrays.copyOf(Arrays.java:3512)
at java.base/java.util.Arrays.copyOf(Arrays.java:3481)
at java.base/java.util.ArrayList.grow(ArrayList.java:237)
at java.base/java.util.ArrayList.grow(ArrayList.java:244)
at java.base/java.util.ArrayList.add(ArrayList.java:454)
at java.base/java.util.ArrayList.add(ArrayList.java:467)
at com.alibaba.fastjson2.reader.ObjectReaderImplList.readObject(ObjectReaderImplList.java:643)
at com.alibaba.fastjson2.JSONReader.read(JSONReader.java:1803)
at com.alibaba.fastjson.JSON.parseArray(JSON.java:2042)
at Issue1184Mutated_547.test_fj(Issue1184Mutated_547.java:19)
Contributor guide
Research direction
Start with the supplied Java reproducer and trace the failing JSON.parseArray call through JSONReader.read and ObjectReaderImplList.readObject, as shown in the stack trace. Compare the fastjson2 and fastjson parse paths for the VerifyDevice enum input. Done means the reproducer no longer ends in OutOfMemoryError and its parsing behavior is verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100