GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — AsciiString.cached(String) should sanitize the provided String (#13749) (#17007) by normanmaurer · Pull Request #17075 · netty/netty

Conversation

@normanmaurer

@normanmaurer normanmaurer commented Jul 9, 2026

Copy link
Copy Markdown
Member

Motivation

AsciiString.cached(String) stored the original String reference
directly in asciiString.string, bypassing the c2b() Latin-1 byte
conversion performed in the constructor. When strings contained
non-Latin-1 characters (>255), the byte array would get '?' in those
positions (via c2b truncation), but toString() still returned the
unsanitized original. This broke the invariant that the cached string
matches the Latin-1 byte content exactly, preventing use of the cached
string for fast equality comparisons (e.g., String::contentEquals with
vectorized JVM intrinsics).

Modification

In AsciiString.cached(String), the method now first sets the cached
string to the original input (preserving identity for fast equals()
checks), then scans the input for non-Latin-1 characters. If any are
found, the cached string is reconstructed from the byte array via
toString(0) to ensure consistency with the Latin-1 byte content. The
Javadoc was updated to document this behavior.

Added 6 test methods (AsciiStringCharacterTest.java) covering pure
ASCII, Latin-1, non-Latin-1 sanitization, empty strings, byte-content
round-trip, and real-world constant preservation. Tests for pure ASCII
and Latin-1 strings assert that the original String identity is
preserved (assertSame).

Result

For pure ASCII/Latin-1 inputs, the original String identity is preserved
(enabling faster equality checks for interned constants).
For non-Latin-1 inputs, the cached string is sanitized to match the
Latin-1 byte content.

Closes #13749

Co-authored-by: Norman Maurer [email protected]

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vpelikh @normanmaurer
AsciiString.cached(String) should sanitize the provided String (#13749)…
4114921
… (#17007)

## Motivation

`AsciiString.cached(String)` stored the original String reference
directly in `asciiString.string`, bypassing the `c2b()` Latin-1 byte
conversion performed in the constructor. When strings contained
non-Latin-1 characters (>255), the byte array would get `'?'` in those
positions (via `c2b` truncation), but `toString()` still returned the
unsanitized original. This broke the invariant that the cached string
matches the Latin-1 byte content exactly, preventing use of the cached
string for fast equality comparisons (e.g., `String::contentEquals` with
vectorized JVM intrinsics).

## Modification

In `AsciiString.cached(String)`, the method now first sets the cached
string to the original input (preserving identity for fast `equals()`
checks), then scans the input for non-Latin-1 characters. If any are
found, the cached string is reconstructed from the byte array via
`toString(0)` to ensure consistency with the Latin-1 byte content. The
Javadoc was updated to document this behavior.

Added 6 test methods (`AsciiStringCharacterTest.java`) covering pure
ASCII, Latin-1, non-Latin-1 sanitization, empty strings, byte-content
round-trip, and real-world constant preservation. Tests for pure ASCII
and Latin-1 strings assert that the original String identity is
preserved (`assertSame`).

## Result

For pure ASCII/Latin-1 inputs, the original String identity is preserved
(enabling faster equality checks for interned constants).
For non-Latin-1 inputs, the cached string is sanitized to match the
Latin-1 byte content.

Closes #13749

Co-authored-by: Norman Maurer <[email protected]>
@normanmaurer
normanmaurer merged commit 24c2e38 into 4.1 Jul 9, 2026
19 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer
normanmaurer deleted the ascii41 branch July 9, 2026 19:42
@lhotari lhotari mentioned this pull request Aug 10, 2026
[fix][sec][branch-4.2] Upgrade Netty to 4.1.137 to address several CVEs and bugs apache/pulsar#26301
Merged
2 of 11 tasks
@github-actions github-actions Bot mentioned this pull request Sep 8, 2026
Bump io.netty:netty-handler from 4.1.119.Final to 4.1.137.Final in /forms-flow-idm/keycloak/idp-selector AOT-Technologies/forms-flow-ai#3362
Closed
@coderabbitai coderabbitai Bot mentioned this pull request Sep 18, 2026
fix(deps): close the amqp-client credential-leak advisory left open on dev OpenResilienceInitiative/ORISO-UserService#1190
Merged
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
@normanmaurer @vpelikh @lltopk
AsciiString.cached(String) should sanitize the provided String (netty…
373c2f0
…#13749) (netty#17007) (netty#17075)

## Motivation

`AsciiString.cached(String)` stored the original String reference
directly in `asciiString.string`, bypassing the `c2b()` Latin-1 byte
conversion performed in the constructor. When strings contained
non-Latin-1 characters (>255), the byte array would get `'?'` in those
positions (via `c2b` truncation), but `toString()` still returned the
unsanitized original. This broke the invariant that the cached string
matches the Latin-1 byte content exactly, preventing use of the cached
string for fast equality comparisons (e.g., `String::contentEquals` with
vectorized JVM intrinsics).

## Modification

In `AsciiString.cached(String)`, the method now first sets the cached
string to the original input (preserving identity for fast `equals()`
checks), then scans the input for non-Latin-1 characters. If any are
found, the cached string is reconstructed from the byte array via
`toString(0)` to ensure consistency with the Latin-1 byte content. The
Javadoc was updated to document this behavior.

Added 6 test methods (`AsciiStringCharacterTest.java`) covering pure
ASCII, Latin-1, non-Latin-1 sanitization, empty strings, byte-content
round-trip, and real-world constant preservation. Tests for pure ASCII
and Latin-1 strings assert that the original String identity is
preserved (`assertSame`).

## Result

For pure ASCII/Latin-1 inputs, the original String identity is preserved
(enabling faster equality checks for interned constants).
For non-Latin-1 inputs, the cached string is sanitized to match the
Latin-1 byte content.

Closes netty#13749

Co-authored-by: Norman Maurer <[email protected]>

Co-authored-by: Vasily Pelikh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@normanmaurer @vpelikh
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.