Skip to content

Reject invalid Unicode scalars in encoded string nodes - #93

Merged
headius merged 2 commits into
jruby:masterfrom
headius:codex/invalid-unicode-scalar-joni-upstream
Nov 19, 2026
Merged

headius merged 2 commits into
jruby:masterfrom
headius:codex/invalid-unicode-scalar-joni-upstream

Conversation

@headius

@headius headius commented Nov 19, 2026

Copy link
Copy Markdown
Member

Joni parses a code point escape into a StringNode. In UTF-16, encoding a surrogate code point can return a non-negative byte count while Encoding.length returns zero. The existing check only rejected negative lengths, so the invalid scalar reached optimizer analysis; OptExactInfo.concatStr then repeatedly received a zero character length and did not advance.

Route StringNode.fromCodePoint through catCode so both construction paths validate the encoded result, and reject zero as well as negative encoded lengths. The regression covers invalid surrogate and out-of-range escapes in UTF-16LE/BE and UTF-32LE/BE, plus valid U+1F600 matching.

Verification

  • Focused: ./mvnw -q -o -Dmaven.repo.local=/home/happier/workspace/jruby/.state/ruby-regexp-security-tests/maven/repository -Dtest=TestInvalidUnicodeEncoding test
  • Full suite: ./mvnw -q -o -Dmaven.repo.local=/home/happier/workspace/jruby/.state/ruby-regexp-security-tests/maven/repository test — all test groups passed on Java 21.

@headius
headius marked this pull request as ready for review November 19, 2026 07:50
@headius
headius merged commit ca40082 into jruby:master Nov 19, 2026
1 check passed
@headius headius added this to the 2.2.9 milestone Nov 19, 2026
@headius headius modified the milestones: 2.2.9, 2.2.11 Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant