Skip to content

Commit

Permalink
throw correct Exception, for issue #1860
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Sep 17, 2023
1 parent c1afa9d commit ee44fb2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
11 changes: 8 additions & 3 deletions core/src/main/java/com/alibaba/fastjson2/JSONReaderUTF16.java
Original file line number Diff line number Diff line change
Expand Up @@ -4580,17 +4580,22 @@ public final void readNumber0() {
}
final int start = offset;

final int limit, multmin;
final int multmin;
if (ch == '-') {
limit = Integer.MIN_VALUE;
if (offset == end) {
throw new JSONException(info("illegal input"));
}

multmin = -214748364; // limit / 10;
negative = true;
ch = chars[offset++];
} else {
if (ch == '+') {
if (offset == end) {
throw new JSONException(info("illegal input"));
}
ch = chars[offset++];
}
limit = -2147483647; // -Integer.MAX_VALUE;
multmin = -214748364; // limit / 10;
}

Expand Down
10 changes: 7 additions & 3 deletions core/src/main/java/com/alibaba/fastjson2/JSONReaderUTF8.java
Original file line number Diff line number Diff line change
Expand Up @@ -6241,17 +6241,21 @@ public final void readNumber0() {

final int start = offset;

final int limit, multmin;
final int multmin;
if (ch == '-') {
limit = Integer.MIN_VALUE;
if (offset == end) {
throw new JSONException(info("illegal input"));
}
multmin = -214748364; // limit / 10;
negative = true;
ch = (char) bytes[offset++];
} else {
if (ch == '+') {
if (offset == end) {
throw new JSONException(info("illegal input"));
}
ch = (char) bytes[offset++];
}
limit = -2147483647; // -Integer.MAX_VALUE;
multmin = -214748364; // limit / 10;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.alibaba.fastjson2.issues_1800;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONException;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertThrows;

public class Issue1860 {
@Test
public void test() {
assertThrows(JSONException.class, () -> JSON.parse("+"));
assertThrows(JSONException.class, () -> JSON.parse("+".getBytes()));

assertThrows(JSONException.class, () -> JSON.parse("-"));
assertThrows(JSONException.class, () -> JSON.parse("-".getBytes()));
}
}

0 comments on commit ee44fb2

Please sign in to comment.