You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2021/11/25 12:11:26 UTC
[tomcat] branch 8.5.x updated: Fix BZ 65677 - improve error handling for HTTP reads with NIO2
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push:
new f350ee7 Fix BZ 65677 - improve error handling for HTTP reads with NIO2
f350ee7 is described below
commit f350ee783e2b33fb55bb5b5d731fb04ba92e4581
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Nov 25 12:08:36 2021 +0000
Fix BZ 65677 - improve error handling for HTTP reads with NIO2
https://bz.apache.org/bugzilla/show_bug.cgi?id=65677
---
java/org/apache/coyote/http11/Http11InputBuffer.java | 17 +++++++++++++++--
webapps/docs/changelog.xml | 4 ++++
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/java/org/apache/coyote/http11/Http11InputBuffer.java b/java/org/apache/coyote/http11/Http11InputBuffer.java
index 8d279dc..2931f78 100644
--- a/java/org/apache/coyote/http11/Http11InputBuffer.java
+++ b/java/org/apache/coyote/http11/Http11InputBuffer.java
@@ -799,7 +799,7 @@ public class Http11InputBuffer implements InputBuffer, ApplicationBufferHandler
}
int nRead = -1;
- byteBuffer.mark();
+ int mark = byteBuffer.position();
try {
if (byteBuffer.position() < byteBuffer.limit()) {
byteBuffer.position(byteBuffer.limit());
@@ -810,7 +810,20 @@ public class Http11InputBuffer implements InputBuffer, ApplicationBufferHandler
// Ensure that the buffer limit and position are returned to a
// consistent "ready for read" state if an error occurs during in
// the above code block.
- byteBuffer.limit(byteBuffer.position()).reset();
+ // Some error conditions can result in the position being reset to
+ // zero which also invalidates the mark.
+ // https://bz.apache.org/bugzilla/show_bug.cgi?id=65677
+ if (byteBuffer.position() >= mark) {
+ // // Position and mark are consistent. Assume a read (possibly
+ // of zero bytes) has occurred.
+ byteBuffer.limit(byteBuffer.position());
+ byteBuffer.position(mark);
+ } else {
+ // Position and mark are inconsistent. Set position and limit to
+ // zero so effectively no data is reported as read.
+ byteBuffer.position(0);
+ byteBuffer.limit(0);
+ }
}
if (log.isDebugEnabled()) {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index dbebe35..bcf9695 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -130,6 +130,10 @@
bug</a> that causes the acceptor to report an incoming connection more
than once. (markt)
</add>
+ <fix>
+ <bug>65677</bug>: Improve exception handling for errors during HTTP/1.1
+ reads with NIO2. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Other">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org