Skip to content

[pull] master from stleary:master - #47

Open
pull[bot] wants to merge 575 commits into
americanstone:masterfrom
stleary:master
Open

pull[bot] wants to merge 575 commits into
americanstone:masterfrom
stleary:master

Conversation

@pull

@pull pull Bot commented Feb 6, 2022 •

Copy link
Copy Markdown

See Commits and Changes for more details.


Created by pull[bot]

Can you help keep this open source service alive? 💖 Please sponsor : )

@pull pull Bot added the ⤵️ pull label Feb 6, 2022
rikkarth and others added 29 commits April 23, 2024 20:52
JSONArray construction improved to recursive validation
JSONTokener implemented smallCharMemory and array level for improved validation
Added new test cases and minor test case adaption
- JSONArray now evaluates EOF accordingly for empty Array inputs.
- JSONTokener fixed indentation
- externalized two JSONMLTest cases
Fixed non-idempotent unit tests in `JSONObjectTest`
fix(#887): complete strictMode for JSONArray
This reverts commit 14f7127, reversing
changes made to 054786e.
This reverts commit d02ac0f, reversing
changes made to cfd4761.
update-jsonpath: update jsonpath from 2.4.0 to 2.9.0
Fix a bug when calling JSONArray.addAll() with Collection as Object
stleary and others added 30 commits July 6, 2026 12:23
Completes the CVE-2026-59171 fix started in ab92bb9 / #1065. The
1000-char length guard in stringToValue admits short exponent-notation
literals (e.g. 1e100000000, 11 chars) which are stored compactly as
BigDecimal and only expand when getBigInteger/optBigInteger calls
BigDecimal.toBigInteger(), materialising ~10^8 digits and stalling the
thread or throwing OOM.

Guard both toBigInteger() sites in objectToBigInteger by rejecting any
BigDecimal whose integer part would exceed
ParserConfiguration.DEFAULT_MAX_NUMBER_LENGTH decimal digits
(precision() - scale(), both O(1) reads). Returns defaultValue on
overflow, matching the method's existing behaviour for non-finite and
unparseable values.

Covers JSONObject.getBigInteger/optBigInteger and
JSONArray.getBigInteger/optBigInteger (all delegate to this helper).

Adds JSONObjectTest.getBigIntegerHugeExponentReturnsDefault with a 5s
timeout so a regression fails fast rather than hanging CI.

Co-Authored-By: Claude <[email protected]>
…Integer

Per review on #1067:
- objectToBigInteger(val, dflt, JSONParserConfiguration) uses
  cfg.getMaxNumberLength() for the digit-count guard; -1 disables it.
  Existing 2-arg form delegates with a default config.
- New public overloads on JSONObject and JSONArray:
  getBigInteger(key, cfg) / optBigInteger(key, dflt, cfg).
  Existing methods delegate with a default config.
- objectToBigDecimal left unchanged (no expansion path; agreed on PR).
- Tests cover default (1000), raised (2000), lowered (5), disabled (-1),
  null config, and JSONArray overloads.

Co-Authored-By: Claude <[email protected]>
#1063: bound BigDecimal→BigInteger expansion in objectToBigInteger (completes CVE-2026-59171 fix)
Max number length config for BigInteger and BigDecimal
XML.mustEscape() is shared by both XML.escape() (serialization) and
XMLTokener.unescapeEntity() (deserialization). While the method's Javadoc
and comment quote the W3C XML 1.0 valid-character range
(#x9 | #xA | #xD | [#x20-#xD7FF] | ...), the implementation only checked
[#x20-#xD7FF] in its range clause, omitting #x9/#xA/#xD.

Although the ISO-control clause excluded those three codepoints, the
negated range clause still marked them as 'must escape', so unescapeEntity()
threw JSONException for the XML-allowed control characters TAB, LF and CR.

This broke XML.unescape("&#10;") and XML.toJSONObject("<a>&#10;</a>"),
both of which worked in v20251224 and regressed after #1045 (v20260522).

Align the range clause with the W3C spec by explicitly allowing #x9, #xA
and #xD, matching the comment that was already documented.

Fixes #1059
XML.toString emitted JSONObject keys verbatim as tag names, so a key
containing '<', '>' or '/' broke out of its element and injected
arbitrary sibling structure into the output. Per #294/#123 the agreed
approach is to throw on invalid input rather than mangle it.

- Add mustBeXmlName / isXmlNameStart / isXmlNameChar implementing the
  XML 1.0 (5th ed.) Name production, code-point aware.
- Validate tagName at method entry and each key at the top of the key
  loop (skipping the cDataTagName sentinel).
- Rewrite XMLTest.shouldHandleIllegalJSONNodeNames and
  XMLConfigurationTest.shouldHandleIllegalJSONNodeNames (previously
  documenting the pass-through behaviour) to assert the throw.
- Add XMLTest.toStringRejectsElementInjectionInKey covering the #1071
  payload and an invalid caller-supplied tagName.
- Add XMLTest.toStringAcceptsValidXmlNames covering hyphen/dot/
  underscore/colon, Latin-1 letters, and the cDataTagName sentinel.

Fixes #1071. Also resolves the long-standing well-formedness question
in #166 / #294 / #308.

Co-Authored-By: Claude <[email protected]>
isXmlNameStart's alternating &&/|| chain scored cognitive complexity 28.
Extracting inRange(cp, lo, hi) collapses it to a flat || sequence and
keeps the range list 1:1 with the XML 1.0 NameStartChar production.
isXmlNameChar updated the same way. No behaviour change.

Co-Authored-By: Claude <[email protected]>
…ntrol-chars

Fix XML.unescape rejecting valid whitespace numeric character references
Per review on #1072: reject only < > & " ' / in element names to
close the CWE-91 injection vector, and drop the full XML 1.0 Name
validation to preserve backwards compatibility for callers that
emit non-well-formed but non-injecting tag names.

Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_01MTGnYg5v1QxaqqfDKHKTVr
#1071: reject invalid XML element names in XML.toString (CWE-91)
Fix strict mode failure when JSONTokener.next() and back() are called before parsing
…ecedence

Apply explicit parser configuration to nested values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.