Skip to content

Commit 4dce036

Browse files
authored
Merge pull request #7895 from alibaba/port/2.0.66.android5
2.0.66.android5: port fixes from main
2 parents a002b98 + f491930 commit 4dce036

19 files changed

Lines changed: 1074 additions & 58 deletions

‎.github/workflows/ci.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
timeout-minutes: 20
1919
strategy:
2020
matrix:
21-
os: [ ubuntu-20.04 ]
21+
os: [ ubuntu-24.04 ]
2222
java: [ 8, 11, 17 ]
2323
fail-fast: false
2424
max-parallel: 16

‎core/src/main/java/com/alibaba/fastjson2/JSONB.java‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,36 @@ static byte[] fromJSONBytes(byte[] jsonUtf8Bytes) {
13411341
return JSONB.toBytes(object);
13421342
}
13431343

1344+
/**
1345+
* Checks if the specified type is an int32 number type
1346+
*
1347+
* @param type the type to check
1348+
* @return true if the type is an int32 number type, false otherwise
1349+
*/
1350+
static boolean isInt32Num(int type) {
1351+
return type >= BC_INT32_NUM_MIN && type <= BC_INT32_NUM_MAX;
1352+
}
1353+
1354+
/**
1355+
* Checks if the specified type is an int32 byte type
1356+
*
1357+
* @param type the type to check
1358+
* @return true if the type is an int32 byte type, false otherwise
1359+
*/
1360+
static boolean isInt32Byte(int type) {
1361+
return (type & 0xF0) == 0x30;
1362+
}
1363+
1364+
/**
1365+
* Checks if the specified type is an int32 short type
1366+
*
1367+
* @param type the type to check
1368+
* @return true if the type is an int32 short type, false otherwise
1369+
*/
1370+
static boolean isInt32Short(int type) {
1371+
return (type & 0xF8) == 0x40;
1372+
}
1373+
13441374
static String typeName(byte type) {
13451375
switch (type) {
13461376
case BC_OBJECT:

‎core/src/main/java/com/alibaba/fastjson2/JSONBDump.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import static com.alibaba.fastjson2.JSONB.Constants.*;
1313
import static com.alibaba.fastjson2.JSONB.typeName;
14+
import static com.alibaba.fastjson2.JSONFactory.checkDecimalScale;
1415
import static com.alibaba.fastjson2.util.JDKUtils.*;
1516

1617
final class JSONBDump {
@@ -242,7 +243,7 @@ private void dumpAny() {
242243
return;
243244
}
244245
case BC_DECIMAL: {
245-
int scale = readInt32Value();
246+
int scale = checkDecimalScale(readInt32Value());
246247
BigInteger unscaledValue;
247248
int type = bytes[offset++];
248249
switch (type) {

‎core/src/main/java/com/alibaba/fastjson2/JSONFactory.java‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ public final class JSONFactory {
4141

4242
static int defaultDecimalMaxScale = 2048;
4343

44+
static int checkDecimalScale(int scale) {
45+
if (scale < -defaultDecimalMaxScale || scale > defaultDecimalMaxScale) {
46+
throw new JSONException("scale overflow : " + scale);
47+
}
48+
return scale;
49+
}
50+
51+
static BigDecimal checkDecimalScale(BigDecimal decimal) {
52+
if (decimal == null) {
53+
return null;
54+
}
55+
checkDecimalScale(decimal.scale());
56+
return decimal;
57+
}
58+
4459
static final class NameCacheEntry2 {
4560
final String name;
4661
final long value0;

‎core/src/main/java/com/alibaba/fastjson2/JSONReader.java‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.*;
2727

2828
import static com.alibaba.fastjson2.JSONFactory.*;
29-
import static com.alibaba.fastjson2.JSONFactory.defaultDecimalMaxScale;
3029
import static com.alibaba.fastjson2.JSONReader.BigIntegerCreator.BIG_INTEGER_CREATOR;
3130
import static com.alibaba.fastjson2.util.TypeUtils.toBigDecimal;
3231
import static com.alibaba.fastjson2.util.TypeUtils.toDoubleValue;
@@ -2610,9 +2609,7 @@ public final Number getNumber() {
26102609
}
26112610
case JSON_TYPE_BIG_DEC: {
26122611
if (scale > 0) {
2613-
if (scale > defaultDecimalMaxScale) {
2614-
throw new JSONException("scale overflow : " + scale);
2615-
}
2612+
checkDecimalScale(scale);
26162613
return toBigDecimal(stringValue);
26172614
} else {
26182615
return new BigInteger(stringValue);

0 commit comments

Comments
 (0)