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 — Fix high-order bit aliasing in HttpUtil.validateToken · netty/netty@021d2f6

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-http/src
    • main/java/io/netty/handler/codec/http
      • HttpUtil.java
    • test/java/io/netty/handler/codec/http
      • HttpUtilTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-http/src/main/java/io/netty/handler/codec/http/HttpUtil.java‎

Copy file name to clipboardExpand all lines: codec-http/src/main/java/io/netty/handler/codec/http/HttpUtil.java
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,10 @@ private static int validateAsciiStringToken(AsciiString token) {
717717
*/
718718
private static int validateCharSequenceToken(CharSequence token) {
719719
for (int i = 0, len = token.length(); i < len; i++) {
720-
byte value = (byte) token.charAt(i);
721-
if (!isValidTokenChar(value)) {
720+
int value = token.charAt(i);
721+
// 1. Check for truncation (anything above 255)
722+
// 2. Check against the BitSet (isValidTokenChar handles 128-255 via bit < 0)
723+
if (value > 0xFF || !isValidTokenChar((byte) value)) {
722724
return i;
723725
}
724726
}
Collapse file

‎codec-http/src/test/java/io/netty/handler/codec/http/HttpUtilTest.java‎

Copy file name to clipboardExpand all lines: codec-http/src/test/java/io/netty/handler/codec/http/HttpUtilTest.java
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,4 +535,22 @@ public void testInvalidTokenChars(char invalidChar) {
535535
assertEquals(2, validateToken(asciiStringToken));
536536
assertEquals(2, validateToken(token));
537537
}
538+
539+
@ParameterizedTest
540+
@ValueSource(chars = {
541+
// High-bit Truncation Candidates (verifying > 0xFF check)
542+
// These characters are chosen because their lower 8 bits
543+
// alias to valid US-ASCII 'tchar' values.
544+
'\u0161', // 0x0161 truncates to 0x61 ('a')
545+
'\u0121', // 0x0121 truncates to 0x21 ('!')
546+
'\u0231', // 0x0231 truncates to 0x31 ('1')
547+
'\u0361' // 0x0361 truncates to 0x61 ('a')
548+
})
549+
public void testInvalidTokenCharsOutsideAsciiRange(char invalidChar) {
550+
// We use a String here because AsciiString would truncate
551+
// the char to a byte during construction.
552+
String token = "GE" + invalidChar + 'T';
553+
assertEquals(2, validateToken(token),
554+
String.format("Character U+%04X should be invalid", (int) invalidChar));
555+
}
538556
}

0 commit comments

Comments
0 (0)
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.