This is an automated email from the ASF dual-hosted git repository.

markt-asf pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/11.0.x by this push:
     new 77e6897e7f Performance: Check for EOF before the numeric test in 
readHostIPv4
77e6897e7f is described below

commit 77e6897e7fa6c8e26ab3a5a13aef318c823f72bc
Author: Chunhui Liu <[email protected]>
AuthorDate: Thu Sep 17 22:38:09 2026 +0800

    Performance: Check for EOF before the numeric test in readHostIPv4
    
    readHostIPv4() called isNumeric() before it checked for end of input.
    isNumeric() probes a 256 element table and relies on an
    ArrayIndexOutOfBoundsException to report an out of range argument, so
    reading to the end of a IPv4 that has no port produced an out of range
    table index and a thrown, then swallowed, exception on every parse.
---
 java/org/apache/tomcat/util/http/parser/HttpParser.java | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/java/org/apache/tomcat/util/http/parser/HttpParser.java 
b/java/org/apache/tomcat/util/http/parser/HttpParser.java
index c1ecf46a64..c433c0b4fd 100644
--- a/java/org/apache/tomcat/util/http/parser/HttpParser.java
+++ b/java/org/apache/tomcat/util/http/parser/HttpParser.java
@@ -917,7 +917,14 @@ public class HttpParser {
         reader.mark(1);
         do {
             c = reader.read();
-            if (c == '.') {
+            if (c == -1) {
+                if (inIPv6) {
+                    throw new 
IllegalArgumentException(sm.getString("http.noClosingBracket"));
+                } else {
+                    pos = -1;
+                    break;
+                }
+            } else if (c == '.') {
                 if (octet > -1 && octet < 256) {
                     // Valid
                     octetCount++;
@@ -951,13 +958,6 @@ public class HttpParser {
                 }
             } else if (c == ':') {
                 break;
-            } else if (c == -1) {
-                if (inIPv6) {
-                    throw new 
IllegalArgumentException(sm.getString("http.noClosingBracket"));
-                } else {
-                    pos = -1;
-                    break;
-                }
             } else if (c == ']') {
                 if (inIPv6) {
                     pos++;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to