Skip to content

Commit 73df32d

Browse files
committed
Fixed issue 3883. Add according unit test.
1 parent dc63608 commit 73df32d

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

core/src/main/java/com/alibaba/fastjson2/JSONReaderUTF16.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3599,6 +3599,9 @@ public void readNumber0() {
35993599

36003600
if (ch == '.') {
36013601
valueType = JSON_TYPE_DEC;
3602+
if (offset == end) {
3603+
throw new JSONException(info("illegal input"));
3604+
}
36023605
ch = chars[offset++];
36033606
while (ch >= '0' && ch <= '9') {
36043607
valid = true;

core/src/main/java/com/alibaba/fastjson2/JSONReaderUTF8.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3298,6 +3298,9 @@ public final void readNumber0() {
32983298

32993299
if (ch == '.') {
33003300
valueType = JSON_TYPE_DEC;
3301+
if (offset == end) {
3302+
throw new JSONException(info("illegal input"));
3303+
}
33013304
ch = bytes[offset++];
33023305
while (ch >= '0' && ch <= '9') {
33033306
valid = true;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.alibaba.fastjson2.issues_3800;
2+
3+
import com.alibaba.fastjson2.JSON;
4+
import com.alibaba.fastjson2.JSONException;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.nio.charset.StandardCharsets;
8+
9+
import static org.junit.jupiter.api.Assertions.assertThrows;
10+
11+
public class Issue3883 {
12+
@Test
13+
public void jsonReaderUTF8ArrayOOBTest() {
14+
String str = ".";
15+
assertThrows(JSONException.class, () -> JSON.parse(str.toCharArray())); // UTF16
16+
assertThrows(JSONException.class, () -> JSON.parse(str.getBytes(StandardCharsets.UTF_8))); // UTF8
17+
assertThrows(JSONException.class, () -> JSON.parse(str)); // JDK 8 UTF16, JDK 9+ UTF8
18+
}
19+
}

0 commit comments

Comments
 (0)