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 e3ce05ba04 Review "Fix zero-length read handling in the input 
stream..."
e3ce05ba04 is described below

commit e3ce05ba042d488c2d202ecc85f25ff95e0e5aba
Author: Mark Thomas <[email protected]>
AuthorDate: Mon Nov 2 12:12:50 2026 +0000

    Review "Fix zero-length read handling in the input stream..."
    
    Negative lengths are invalid
    Expand checks on provided arguments for read
---
 .../apache/coyote/http11/upgrade/UpgradeServletInputStream.java   | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git 
a/java/org/apache/coyote/http11/upgrade/UpgradeServletInputStream.java 
b/java/org/apache/coyote/http11/upgrade/UpgradeServletInputStream.java
index ea7e78806b..b5f16dfeaa 100644
--- a/java/org/apache/coyote/http11/upgrade/UpgradeServletInputStream.java
+++ b/java/org/apache/coyote/http11/upgrade/UpgradeServletInputStream.java
@@ -17,6 +17,7 @@
 package org.apache.coyote.http11.upgrade;
 
 import java.io.IOException;
+import java.util.Objects;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import jakarta.servlet.ReadListener;
@@ -176,10 +177,12 @@ public class UpgradeServletInputStream extends 
ServletInputStream {
     @Override
     public final int readLine(byte[] b, int off, int len) throws IOException {
         preReadChecks();
+        Objects.checkFromIndexSize(off, len, b.length);
 
-        if (len <= 0) {
+        if (len == 0) {
             return 0;
         }
+
         int count = 0, c;
 
         while ((c = readInternal()) != -1) {
@@ -201,9 +204,10 @@ public class UpgradeServletInputStream extends 
ServletInputStream {
     @Override
     public final int read(byte[] b, int off, int len) throws IOException {
         preReadChecks();
+        Objects.checkFromIndexSize(off, len, b.length);
 
         // The input must not be touched if the caller requested zero bytes.
-        if (len <= 0) {
+        if (len == 0) {
             return 0;
         }
 


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

Reply via email to