This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 4bb3fee Fix BZ 65677 - improve error handling for HTTP reads with NIO2
4bb3fee is described below
commit 4bb3fee348fe30f8100cdf75cbc0d382105baeb6
Author: Mark Thomas <[email protected]>
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 f1346f1..413a1c4 100644
--- a/java/org/apache/coyote/http11/Http11InputBuffer.java
+++ b/java/org/apache/coyote/http11/Http11InputBuffer.java
@@ -794,7 +794,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 6075bfc..15455c9 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -137,6 +137,10 @@
Avoid unnecessary duplicate read registrations for blocking I/O with
the
NIO connector. (markt)
</fix>
+ <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: [email protected]
For additional commands, e-mail: [email protected]