Repository navigation
Commit 3f78e99
2.0.66.android8: port fixes from main
* fix: bound JSONB decimal scale to prevent excessive CPU usage (#7857)
Mirror of main's six-commit hardening series (35d225b, 9d43412,
29efe4d, 73bac1f, c27f0e7, 333cb52, merged as PR #7858). A
hostile BC_DECIMAL record can carry an enormous scale (CPU burn inside
BigDecimal), a nested decimal as its own scale field (unbounded
recursion to StackOverflowError), or a non-int32 scale encoding. The
port adds JSONFactory.checkDecimalScale(int)/(BigDecimal), routes every
BC_DECIMAL read in JSONReaderJSONB through the new readDecimalScale /
readDecimalUnscaled / checkDecimalScaleSum guards (8 switch arms plus
the readBigDecimal fast paths and skipValue), caps decimal
scale/unscaled nesting at MAX_DECIMAL_LEVEL = 128 (small-stack margin),
wraps string-to-BigDecimal conversions with checkDecimalScale, and
guards the writer side (JSONWriterJSONB.writeDecimal) and JSONBDump the
same way. main's isInt32Num/isInt32Byte/isInt32Short helpers are added
to JSONB (this branch did not have them).
Branch adaptations:
- JSONReaderJSONB gains `import static com.alibaba.fastjson2.JSONB.*;`
(mirroring main's import shape) in place of the JSONB.typeName
single-type import; unqualified calls do not resolve across classes
without it.
- The readBigDecimal fast paths keep this branch's getInt/UNSAFE.getLong
forms (no getIntBE/check3/check7 here); only the guards are added.
- readFloatValue/readDoubleValue BC_DECIMAL arms also take main's
intValue -> floatValue/doubleValue corrections; this branch had the
same latent bug.
- FieldReaderBigDecimalField gains main's FieldReaderBigDecimal
NullOnError branch (try/catch -> null when the feature is set).
Eleven sibling readers on this branch already implement NullOnError;
the field-based BigDecimal reader did not, so the ported resync
contract (the record is fully consumed before the throw and
NullOnError readers resume at the record boundary) had no consumer
here, and the three nullOnError* tests in Issue7857 could not pass.
(cherry picked from the PR #7858 series, manually applied)
* fix: WriteClassName produces illegal JSON for NaN and Infinity (#7783)
Mirror of main 6fd9ba1. Non-finite values must not take the D/F
suffix: Double.isFinite / Float.isFinite are added to the existing
WriteClassName condition, keeping this branch's simpler condition shape
(no WriteNonStringKeyAsString / NotWriteNumberClassName checks here).
Test adaptation: Issue7783 is ported without test_specialAsString --
JSONWriter.Feature.WriteFloatSpecialAsString does not exist on this
branch.
(cherry picked from commit 6fd9ba1, manually applied)
* fix: treat format "string" as WriteNonStringValueAsString for BigDecimal (#7734)
Mirror of main 7da8818. The "string" sentinel (from
@jsonformat(shape = STRING) on main, or @JSONField(format = "string")
here) must not be compiled into a DecimalFormat pattern. Ports the
FieldWriter constructor guard and the BigDecimal / BigDecimal[] writer
resolution arms.
Branch adaptations:
- main's ObjectWriterProvider.getObjectWriter(Type, String, Locale)
hunk is not applicable: the method does not exist on this branch.
- FieldWriterDoubleField now reads this.features when computing
writeNonStringValueAsString. The base FieldWriter constructor ORs the
sentinel bit into its own parameter before assigning this.features;
the subclass captured the flag from its own (unmodified) parameter,
so the sentinel was silently lost for Double fields. main reads the
feature at write time and is unaffected. The same capture pattern
remains in FieldWriterDoubleMethod / FieldWriterFloatMethod /
FieldWriterInt16 / FieldWriterInt8 -- out of the ported suite's
scope.
- Issue7734 is adapted to drive the sentinel through
@JSONField(format = "string"): this branch's BeanUtils does not
process @jsonformat, while the FieldWriter sentinel ->
WriteNonStringValueAsString mapping (FieldWriter.java:74) makes the
@JSONField path exercise the same contract. 4/4 green.
(cherry picked from commit 7da8818, manually applied)
* fix: validate cached field writer by value type in toJSONObject (#7714)
Mirror of main 6c29d27 + 514f3af (merged as PR #7739). Ports
FieldWriterObject.isTypeMatch (final form, with the null guard and
javadoc), the getObjectWriter refactor to share the predicate, and the
ObjectWriterAdapter.toJSONObject re-resolution block including the
JSON.toJSON conversion for non-adapter writers. This branch's
toJSONObject had the same unguarded reuse (issue #7714:
ClassCastException wrapped as "key get error", and subclass values
silently dropped). Issue7714 ported verbatim, 4/4 green.
(cherry picked from commits 6c29d27 and 514f3af, manually applied)
* fix: use own ClassLoader as parent when context ClassLoader loads a foreign fastjson2 (#7869)
Not applicable to this branch -- DynamicClassLoader does not exist here
(no ASM codegen), so the foreign-parent failure mode of main #7873
cannot occur.
* fix: the getter method is discarded when serializing character fields (#7719)
Not applicable to this branch -- main's shared FieldWriterCharValue /
FieldWriterChar constructors dropped the method argument; here
ObjectWriterCreator always passes the getter to FieldWriterCharMethod
(ObjectWriterCreator.java:876) and FieldWriterCharMethod invokes it
(line 31). The guard test was already ported from main 7c4609f as
ObjectWriter14Test; it is extended with the f2 assertions from
d5c30ac (primitive char getter returning lowercase while the backing
field holds uppercase), adapted to this branch's JSONPath.of().eval()
spelling. 3/3 green.
Verification: 34 ported tests green (Issue7857 19, Issue7783 4,
Issue7734 4, Issue7714 4, ObjectWriter14Test 3); full core suite
BUILD SUCCESS (JDK 8).
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>1 parent 8355a57 commit 3f78e99
18 files changed
Lines changed: 1073 additions & 56 deletions
File tree
- core/src
- main/java/com/alibaba/fastjson2
- reader
- writer
- test/java/com/alibaba/fastjson2
- issues_7000
- issues_7800
- issues
- writer
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1345 | 1345 | | |
1346 | 1346 | | |
1347 | 1347 | | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
1348 | 1378 | | |
1349 | 1379 | | |
1350 | 1380 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
241 | 242 | | |
242 | 243 | | |
243 | 244 | | |
244 | | - | |
| 245 | + | |
245 | 246 | | |
246 | 247 | | |
247 | 248 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
47 | 62 | | |
48 | 63 | | |
49 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2673 | 2673 | | |
2674 | 2674 | | |
2675 | 2675 | | |
2676 | | - | |
2677 | | - | |
2678 | | - | |
| 2676 | + | |
2679 | 2677 | | |
2680 | 2678 | | |
2681 | 2679 | | |
| |||
0 commit comments