Re: [tomcat] branch main updated: Avoid unchecked use of the backing array

2023-04-21 Thread Christopher Schultz

Rémy,

On 4/21/23 03:53, r...@apache.org wrote:

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

remm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
  new 4d963f8c51 Avoid unchecked use of the backing array
4d963f8c51 is described below

commit 4d963f8c51cfc20abd983932f66c61d7d92026c5
Author: remm 
AuthorDate: Fri Apr 21 09:52:54 2023 +0200

 Avoid unchecked use of the backing array
 
 This comes from user code and can happen with a direct (bad idea ...) or

 read only buffer. This will cause inefficient byte copying.
 Also review all other uses of .array() in Tomcat, which all seem safe.
---
  java/org/apache/tomcat/websocket/PerMessageDeflate.java | 12 +---
  webapps/docs/changelog.xml  |  8 
  2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/java/org/apache/tomcat/websocket/PerMessageDeflate.java 
b/java/org/apache/tomcat/websocket/PerMessageDeflate.java
index 482c5c1d2d..665cfd24f4 100644
--- a/java/org/apache/tomcat/websocket/PerMessageDeflate.java
+++ b/java/org/apache/tomcat/websocket/PerMessageDeflate.java
@@ -329,9 +329,15 @@ public class PerMessageDeflate implements Transformation {
  ByteBuffer uncompressedPayload = 
uncompressedPart.getPayload();
  SendHandler uncompressedIntermediateHandler = 
uncompressedPart.getIntermediateHandler();
  
-deflater.setInput(uncompressedPayload.array(),

-uncompressedPayload.arrayOffset() + 
uncompressedPayload.position(),
-uncompressedPayload.remaining());
+if (uncompressedPayload.hasArray()) {
+deflater.setInput(uncompressedPayload.array(),
+uncompressedPayload.arrayOffset() + 
uncompressedPayload.position(),
+uncompressedPayload.remaining());
+} else {
+byte[] bytes = new byte[uncompressedPayload.remaining()];
+uncompressedPayload.get(bytes);
+deflater.setInput(bytes, 0, bytes.length);


What about deflater.setInput(uncompressedPayload)?

I read through the code and it looks like it will use an 
unsafe-read-only-peek into the buffer. It may perform better; I'm not 
sure if it behaves exactly how you want.


-chris

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



JsonAccessLogValve

2023-04-21 Thread Rainer Jung

Hi all,

I am looking at the new access log valve to add support for the pattern 
fields with sub keys (headers, attributes etc.).


Many of those have free text values, so ensuring correct encodig is 
important. I noticed, that the AbstractAccessLogValve already does 
almost correct JSON encoding and the Json one ensures correct JSON 
encoding by again encoding the values coming out of the 
AbstractAccessLogValve. So an encoded char in a header ends up as \\u... 
in the log, not as \u


Since the encoding of the base valve is already so close to JSON, I 
wonder, whether we could remove the only difference that's there and 
then get rid of the double encoding: a vertical tab gets encoded as "\v" 
which is not known in JSON. For JSON it needs to get encoded using an \u 
sequence. We do that already for most other rarely used control 
characters. The only other characters that are simply "\"-escaped are 
also allowed in that form in JSON, so are fine.


So what about switching the encoding of vertical tab in the Abstract 
valve to \u00? Of course for TC 11 that should not be a problem, but do 
people think it would be OK to backport? It doesnt sound like a common 
character to expect, \v is not so well-known as a representation and 
using \u-style would be more consistent with any other characters. \v is 
not even a valid Java character escape (though that's not a strong 
argument here).


WDYT?

Thanks and regards,

Rainer


-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



Buildbot success in on tomcat-9.0.x

2023-04-21 Thread buildbot
Build status: Build succeeded!
Worker used: bb_worker2_ubuntu
URL: https://ci2.apache.org/#builders/37/builds/526
Blamelist: Rainer Jung , remm 
Build Text: build successful
Status Detected: restored build
Build Source Stamp: [branch 9.0.x] c7e83cfda180888ee5308e90a6fd5f1c23e6bf89


Steps:

  worker_preparation: 0

  git: 0

  shell: 0

  shell_1: 0

  shell_2: 0

  shell_3: 0

  shell_4: 0

  shell_5: 0

  compile: 1

  shell_6: 0

  shell_7: 0

  shell_8: 0

  shell_9: 0

  Rsync docs to nightlies.apache.org: 0

  shell_10: 0

  Rsync RAT to nightlies.apache.org: 0

  compile_1: 1

  shell_11: 0

  Rsync Logs to nightlies.apache.org: 0


-- ASF Buildbot


-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[tomcat] branch 9.0.x updated: Improve docs for access log valves.

2023-04-21 Thread rjung
This is an automated email from the ASF dual-hosted git repository.

rjung 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 c7e83cfda1 Improve docs for access log valves.
c7e83cfda1 is described below

commit c7e83cfda180888ee5308e90a6fd5f1c23e6bf89
Author: Rainer Jung 
AuthorDate: Fri Apr 21 13:48:12 2023 +0200

Improve docs for access log valves.

- sort pattern identifier lists alphabetically.
  Easier to find things than in a mxied alphabetical/context sorted list.
- document special cases (handling of unknown pattern indentifiers)
- list limitations of JsonAccessLogValve
- remove redundant field value info from JsonAccessLogValve,
  refer to AccessLogValve values instead.
---
 webapps/docs/config/valve.xml | 58 +--
 1 file changed, 39 insertions(+), 19 deletions(-)

diff --git a/webapps/docs/config/valve.xml b/webapps/docs/config/valve.xml
index 936c02b227..895c9291f9 100644
--- a/webapps/docs/config/valve.xml
+++ b/webapps/docs/config/valve.xml
@@ -288,9 +288,14 @@
 %A - Local IP address
 %b - Bytes sent, excluding HTTP headers, or '-' if 
zero
 %B - Bytes sent, excluding HTTP headers
+%D - Time taken to process the request in millis. 
Note: In
+httpd %D is microseconds. Behaviour will be aligned to httpd
+in Tomcat 10 onwards.
+%F - Time taken to commit the response, in 
milliseconds
 %h - Remote host name (or IP address if
 enableLookups for the connector is false)
 %H - Request protocol
+%I - Current request thread name (can compare 
later with stacktraces)
 %l - Remote logical username from identd (always 
returns
 '-')
 %m - Request method (GET, POST, etc.)
@@ -301,18 +306,13 @@
 %s - HTTP status code of the response
 %S - User session ID
 %t - Date and time, in Common Log Format
-%u - Remote user that was authenticated (if any), 
else '-' (escaped if required)
-%U - Requested URL path
-%v - Local server name
-%D - Time taken to process the request in millis. 
Note: In
-httpd %D is microseconds. Behaviour will be aligned to httpd
-in Tomcat 10 onwards.
 %T - Time taken to process the request, in 
seconds. Note: This
 value has millisecond resolution whereas in httpd it has
 second resolution. Behaviour will be align to httpd
 in Tomcat 10 onwards.
-%F - Time taken to commit the response, in 
milliseconds
-%I - Current request thread name (can compare 
later with stacktraces)
+%u - Remote user that was authenticated (if any), 
else '-' (escaped if required)
+%U - Requested URL path
+%v - Local server name
 %X - Connection status when response is completed:
   
 X = Connection aborted before the response 
completed.
@@ -336,8 +336,8 @@
 %{xxx}i write value of incoming header with name 
xxx (escaped if required)
 %{xxx}o write value of outgoing header with name 
xxx (escaped if required)
 %{xxx}c write value of cookie(s) with name 
xxx (comma separated and escaped if required)
-%{xxx}r write value of ServletRequest attribute 
with name xxx (escaped if required)
-%{xxx}s write value of HttpSession attribute with 
name xxx (escaped if required)
+%{xxx}r write value of ServletRequest attribute 
with name xxx (escaped if required, value ?? if 
request is null)
+%{xxx}s write value of HttpSession attribute with 
name xxx (escaped if required, value ?? if request is 
null)
 %{xxx}p write local (server) port 
(xxx==local) or
 remote (client) port (xxx=remote)
 %{xxx}t write timestamp at the end of the request 
formatted using the
@@ -384,6 +384,10 @@
 appends the values of the Referer and User-Agent
 headers, each in double quotes, to the common pattern.
 
+Fields using unknown pattern identifiers will be logged as 
???X???
+where X is the unknown identifier. Fields with unknown 
pattern identifier
+plus {xxx} key will be logged as ???.
+
 When Tomcat is operating behind a reverse proxy, the client information
 logged by the Access Log Valve may represent the reverse proxy, the browser
 or some combination of the two depending on the configuration of Tomcat and
@@ -509,9 +513,9 @@
   
 
 The JSON Access Log Valve extends the
-Access Log Valve class, and so
+Access Log Valve, and so
 uses the same self-contained logging logic.  This means it
-implements many of the same file handling attributes.  The main
+implements the same file handling attributes.  The main
 difference to the standard AccessLogValve is that
 JsonAccessLogValve creates log files which
 follow the JSON syntax as defined by
@@ -536,18 +540,32 @@
 
 
 
-While the pattern supported are the same as for the regular access log,
-those are mapped to 

[tomcat] branch 10.1.x updated: Improve docs for access log valves.

2023-04-21 Thread rjung
This is an automated email from the ASF dual-hosted git repository.

rjung pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.1.x by this push:
 new e536d39387 Improve docs for access log valves.
e536d39387 is described below

commit e536d3938768f89d5580ff9d0083d988c7d66890
Author: Rainer Jung 
AuthorDate: Fri Apr 21 13:45:47 2023 +0200

Improve docs for access log valves.

- sort pattern identifier lists alphabetically.
  Easier to find things than in a mxied alphabetical/context sorted list.
- document special cases (handling of unknown pattern indentifiers)
- list limitations of JsonAccessLogValve
- remove redundant field value info from JsonAccessLogValve,
  refer to AccessLogValve values instead.
---
 webapps/docs/config/valve.xml | 50 ++-
 1 file changed, 35 insertions(+), 15 deletions(-)

diff --git a/webapps/docs/config/valve.xml b/webapps/docs/config/valve.xml
index f065a2181a..6170c474c3 100644
--- a/webapps/docs/config/valve.xml
+++ b/webapps/docs/config/valve.xml
@@ -288,9 +288,12 @@
 %A - Local IP address
 %b - Bytes sent, excluding HTTP headers, or '-' if 
zero
 %B - Bytes sent, excluding HTTP headers
+%D - Time taken to process the request in 
microseconds
+%F - Time taken to commit the response, in 
milliseconds
 %h - Remote host name (or IP address if
 enableLookups for the connector is false)
 %H - Request protocol
+%I - Current request thread name (can compare 
later with stacktraces)
 %l - Remote logical username from identd (always 
returns
 '-')
 %m - Request method (GET, POST, etc.)
@@ -301,13 +304,10 @@
 %s - HTTP status code of the response
 %S - User session ID
 %t - Date and time, in Common Log Format
+%T - Time taken to process the request, in 
seconds
 %u - Remote user that was authenticated (if any), 
else '-' (escaped if required)
 %U - Requested URL path
 %v - Local server name
-%D - Time taken to process the request in 
microseconds
-%T - Time taken to process the request, in 
seconds
-%F - Time taken to commit the response, in 
milliseconds
-%I - Current request thread name (can compare 
later with stacktraces)
 %X - Connection status when response is completed:
   
   X = Connection aborted before the response 
completed.
@@ -331,8 +331,8 @@
 %{xxx}i write value of incoming header with name 
xxx (escaped if required)
 %{xxx}o write value of outgoing header with name 
xxx (escaped if required)
 %{xxx}c write value of cookie(s) with name 
xxx (comma separated and escaped if required)
-%{xxx}r write value of ServletRequest attribute 
with name xxx (escaped if required)
-%{xxx}s write value of HttpSession attribute with 
name xxx (escaped if required)
+%{xxx}r write value of ServletRequest attribute 
with name xxx (escaped if required, value ?? if 
request is null)
+%{xxx}s write value of HttpSession attribute with 
name xxx (escaped if required, value ?? if request is 
null)
 %{xxx}p write local (server) port 
(xxx==local) or
 remote (client) port (xxx=remote)
 %{xxx}t write timestamp at the end of the request 
formatted using the
@@ -383,6 +383,10 @@
 appends the values of the Referer and User-Agent
 headers, each in double quotes, to the common pattern.
 
+Fields using unknown pattern identifiers will be logged as 
???X???
+where X is the unknown identifier. Fields with unknown 
pattern identifier
+plus {xxx} key will be logged as ???.
+
 When Tomcat is operating behind a reverse proxy, the client information
 logged by the Access Log Valve may represent the reverse proxy, the browser
 or some combination of the two depending on the configuration of Tomcat and
@@ -508,9 +512,9 @@
   
 
 The JSON Access Log Valve extends the
-Access Log Valve class, and so
+Access Log Valve, and so
 uses the same self-contained logging logic.  This means it
-implements many of the same file handling attributes.  The main
+implements the same file handling attributes.  The main
 difference to the standard AccessLogValve is that
 JsonAccessLogValve creates log files which
 follow the JSON syntax as defined by
@@ -535,18 +539,32 @@
 
 
 
-While the pattern supported are the same as for the regular access log,
-those are mapped to specific JSON attribute names. The attributes are the
-following:
+While the patterns supported are the same as for the regular
+Access Log Valve,
+there are a few differences:
+
+requests are logged as JSON objects. Each "%" prefixed pattern
+identifier results in a key value pair in this object.
+See below for the list of keys used for the respective pattern
+identifiers.
+the values logged are the same as the 

[tomcat] branch main updated: Improve docs for access log valves.

2023-04-21 Thread rjung
This is an automated email from the ASF dual-hosted git repository.

rjung pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
 new 2ef1ec2062 Improve docs for access log valves.
 new a9bdd19263 Merge branch 'main' of 
https://gitbox.apache.org/repos/asf/tomcat
2ef1ec2062 is described below

commit 2ef1ec20629566d4e257cf276ed74273d58e2774
Author: Rainer Jung 
AuthorDate: Fri Apr 21 13:43:10 2023 +0200

Improve docs for access log valves.

- sort pattern identifier lists alphabetically.
  Easier to find things than in a mxied alphabetical/context sorted list.
- document special cases (handling of unknown pattern indentifiers)
- list limitations of JsonAccessLogValve
- remove redundant field value info from JsonAccessLogValve,
  refer to AccessLogValve values instead.
---
 webapps/docs/config/valve.xml | 50 ++-
 1 file changed, 35 insertions(+), 15 deletions(-)

diff --git a/webapps/docs/config/valve.xml b/webapps/docs/config/valve.xml
index 2c15ed6697..c0af86da54 100644
--- a/webapps/docs/config/valve.xml
+++ b/webapps/docs/config/valve.xml
@@ -288,9 +288,12 @@
 %A - Local IP address
 %b - Bytes sent, excluding HTTP headers, or '-' if 
zero
 %B - Bytes sent, excluding HTTP headers
+%D - Time taken to process the request in 
microseconds
+%F - Time taken to commit the response, in 
milliseconds
 %h - Remote host name (or IP address if
 enableLookups for the connector is false)
 %H - Request protocol
+%I - Current request thread name (can compare 
later with stacktraces)
 %l - Remote logical username from identd (always 
returns
 '-')
 %m - Request method (GET, POST, etc.)
@@ -301,13 +304,10 @@
 %s - HTTP status code of the response
 %S - User session ID
 %t - Date and time, in Common Log Format
+%T - Time taken to process the request, in 
seconds
 %u - Remote user that was authenticated (if any), 
else '-' (escaped if required)
 %U - Requested URL path
 %v - Local server name
-%D - Time taken to process the request in 
microseconds
-%T - Time taken to process the request, in 
seconds
-%F - Time taken to commit the response, in 
milliseconds
-%I - Current request thread name (can compare 
later with stacktraces)
 %X - Connection status when response is completed:
   
   X = Connection aborted before the response 
completed.
@@ -331,8 +331,8 @@
 %{xxx}i write value of incoming header with name 
xxx (escaped if required)
 %{xxx}o write value of outgoing header with name 
xxx (escaped if required)
 %{xxx}c write value of cookie(s) with name 
xxx (comma separated and escaped if required)
-%{xxx}r write value of ServletRequest attribute 
with name xxx (escaped if required)
-%{xxx}s write value of HttpSession attribute with 
name xxx (escaped if required)
+%{xxx}r write value of ServletRequest attribute 
with name xxx (escaped if required, value ?? if 
request is null)
+%{xxx}s write value of HttpSession attribute with 
name xxx (escaped if required, value ?? if request is 
null)
 %{xxx}p write local (server) port 
(xxx==local) or
 remote (client) port (xxx=remote)
 %{xxx}t write timestamp at the end of the request 
formatted using the
@@ -383,6 +383,10 @@
 appends the values of the Referer and User-Agent
 headers, each in double quotes, to the common pattern.
 
+Fields using unknown pattern identifiers will be logged as 
???X???
+where X is the unknown identifier. Fields with unknown 
pattern identifier
+plus {xxx} key will be logged as ???.
+
 When Tomcat is operating behind a reverse proxy, the client information
 logged by the Access Log Valve may represent the reverse proxy, the browser
 or some combination of the two depending on the configuration of Tomcat and
@@ -508,9 +512,9 @@
   
 
 The JSON Access Log Valve extends the
-Access Log Valve class, and so
+Access Log Valve, and so
 uses the same self-contained logging logic.  This means it
-implements many of the same file handling attributes.  The main
+implements the same file handling attributes.  The main
 difference to the standard AccessLogValve is that
 JsonAccessLogValve creates log files which
 follow the JSON syntax as defined by
@@ -535,18 +539,32 @@
 
 
 
-While the pattern supported are the same as for the regular access log,
-those are mapped to specific JSON attribute names. The attributes are the
-following:
+While the patterns supported are the same as for the regular
+Access Log Valve,
+there are a few differences:
+
+requests are logged as JSON objects. Each "%" prefixed pattern
+identifier results in a key value pair in this object.
+See below for the list of keys used for the 

Buildbot failure in on tomcat-9.0.x

2023-04-21 Thread buildbot
Build status: BUILD FAILED: failed compile (failure)
Worker used: bb_worker2_ubuntu
URL: https://ci2.apache.org/#builders/37/builds/525
Blamelist: remm 
Build Text: failed compile (failure)
Status Detected: new failure
Build Source Stamp: [branch 9.0.x] 7cd2947b83e75600138d2ee3a358834ece48fd9b


Steps:

  worker_preparation: 0

  git: 0

  shell: 0

  shell_1: 0

  shell_2: 0

  shell_3: 0

  shell_4: 0

  shell_5: 0

  compile: 1

  shell_6: 0

  shell_7: 0

  shell_8: 0

  shell_9: 0

  Rsync docs to nightlies.apache.org: 0

  shell_10: 0

  Rsync RAT to nightlies.apache.org: 0

  compile_1: 2

  shell_11: 0

  Rsync Logs to nightlies.apache.org: 0


-- ASF Buildbot


-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[Bug 66574] Deadlock in websocket code

2023-04-21 Thread bugzilla
https://bz.apache.org/bugzilla/show_bug.cgi?id=66574

--- Comment #5 from Remy Maucherat  ---
Well, it seems like it is triggered by your code.
"thread" #824 decides to wait in your code, blocking inside the main Servlet
request processing (so it is still holding the socket wrapper lock).
"thread" #1 is simply doing Tomcat shutdown, closing the websocket sessions in
the process.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[Bug 66575] Use of ByteBuffer.array() not guarded by hasArray()

2023-04-21 Thread bugzilla
https://bz.apache.org/bugzilla/show_bug.cgi?id=66575

Remy Maucherat  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|NEW |RESOLVED

--- Comment #6 from Remy Maucherat  ---
I shouldn't have asked for an explanation, user code can use direct or read
only BB if it wants to, so it has to be supported.
The fix will be in 11.0.0-M6, 10.1.9, 9.0.75, 8.5.89.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[tomcat] branch 8.5.x updated: Avoid unchecked use of the backing array

2023-04-21 Thread remm
This is an automated email from the ASF dual-hosted git repository.

remm 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 f0f052626f Avoid unchecked use of the backing array
f0f052626f is described below

commit f0f052626fdbb0d6ca2af743a6e45737c6fd65bc
Author: remm 
AuthorDate: Fri Apr 21 09:52:54 2023 +0200

Avoid unchecked use of the backing array

This comes from user code and can happen with a direct (bad idea ...) or
read only buffer. This will cause inefficient byte copying.
Also review all other uses of .array() in Tomcat, which all seem safe.
---
 java/org/apache/tomcat/websocket/PerMessageDeflate.java | 12 +---
 webapps/docs/changelog.xml  |  8 
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/java/org/apache/tomcat/websocket/PerMessageDeflate.java 
b/java/org/apache/tomcat/websocket/PerMessageDeflate.java
index 4bc97b8199..a7a9fb4524 100644
--- a/java/org/apache/tomcat/websocket/PerMessageDeflate.java
+++ b/java/org/apache/tomcat/websocket/PerMessageDeflate.java
@@ -329,9 +329,15 @@ public class PerMessageDeflate implements Transformation {
 ByteBuffer uncompressedPayload = uncompressedPart.getPayload();
 SendHandler uncompressedIntermediateHandler = 
uncompressedPart.getIntermediateHandler();
 
-deflater.setInput(uncompressedPayload.array(),
-uncompressedPayload.arrayOffset() + 
uncompressedPayload.position(),
-uncompressedPayload.remaining());
+if (uncompressedPayload.hasArray()) {
+deflater.setInput(uncompressedPayload.array(),
+uncompressedPayload.arrayOffset() + 
uncompressedPayload.position(),
+uncompressedPayload.remaining());
+} else {
+byte[] bytes = new byte[uncompressedPayload.remaining()];
+uncompressedPayload.get(bytes);
+deflater.setInput(bytes, 0, bytes.length);
+}
 
 int flush = (uncompressedPart.isFin() ? Deflater.SYNC_FLUSH : 
Deflater.NO_FLUSH);
 boolean deflateRequired = true;
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 5bb0b25529..56a28fbad0 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -121,6 +121,14 @@
   
 
   
+  
+
+  
+66575: Avoid unchecked use of the backing array of a
+buffer provided by the user in the compression transformation. (remm)
+  
+
+  
 
 
   


-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[tomcat] branch 9.0.x updated: Avoid unchecked use of the backing array

2023-04-21 Thread remm
This is an automated email from the ASF dual-hosted git repository.

remm 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 7cd2947b83 Avoid unchecked use of the backing array
7cd2947b83 is described below

commit 7cd2947b83e75600138d2ee3a358834ece48fd9b
Author: remm 
AuthorDate: Fri Apr 21 09:52:54 2023 +0200

Avoid unchecked use of the backing array

This comes from user code and can happen with a direct (bad idea ...) or
read only buffer. This will cause inefficient byte copying.
Also review all other uses of .array() in Tomcat, which all seem safe.
---
 java/org/apache/tomcat/websocket/PerMessageDeflate.java | 12 +---
 webapps/docs/changelog.xml  |  8 
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/java/org/apache/tomcat/websocket/PerMessageDeflate.java 
b/java/org/apache/tomcat/websocket/PerMessageDeflate.java
index 4bc97b8199..a7a9fb4524 100644
--- a/java/org/apache/tomcat/websocket/PerMessageDeflate.java
+++ b/java/org/apache/tomcat/websocket/PerMessageDeflate.java
@@ -329,9 +329,15 @@ public class PerMessageDeflate implements Transformation {
 ByteBuffer uncompressedPayload = uncompressedPart.getPayload();
 SendHandler uncompressedIntermediateHandler = 
uncompressedPart.getIntermediateHandler();
 
-deflater.setInput(uncompressedPayload.array(),
-uncompressedPayload.arrayOffset() + 
uncompressedPayload.position(),
-uncompressedPayload.remaining());
+if (uncompressedPayload.hasArray()) {
+deflater.setInput(uncompressedPayload.array(),
+uncompressedPayload.arrayOffset() + 
uncompressedPayload.position(),
+uncompressedPayload.remaining());
+} else {
+byte[] bytes = new byte[uncompressedPayload.remaining()];
+uncompressedPayload.get(bytes);
+deflater.setInput(bytes, 0, bytes.length);
+}
 
 int flush = (uncompressedPart.isFin() ? Deflater.SYNC_FLUSH : 
Deflater.NO_FLUSH);
 boolean deflateRequired = true;
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 57ad80dd43..c0c2383e6c 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -121,6 +121,14 @@
   
 
   
+  
+
+  
+66575: Avoid unchecked use of the backing array of a
+buffer provided by the user in the compression transformation. (remm)
+  
+
+  
 
 
   


-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[tomcat] branch 10.1.x updated: Avoid unchecked use of the backing array

2023-04-21 Thread remm
This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.1.x by this push:
 new e51b498e57 Avoid unchecked use of the backing array
e51b498e57 is described below

commit e51b498e5730c0a8dc34618947d265d034566a0d
Author: remm 
AuthorDate: Fri Apr 21 09:52:54 2023 +0200

Avoid unchecked use of the backing array

This comes from user code and can happen with a direct (bad idea ...) or
read only buffer. This will cause inefficient byte copying.
Also review all other uses of .array() in Tomcat, which all seem safe.
---
 java/org/apache/tomcat/websocket/PerMessageDeflate.java | 12 +---
 webapps/docs/changelog.xml  |  8 
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/java/org/apache/tomcat/websocket/PerMessageDeflate.java 
b/java/org/apache/tomcat/websocket/PerMessageDeflate.java
index 482c5c1d2d..665cfd24f4 100644
--- a/java/org/apache/tomcat/websocket/PerMessageDeflate.java
+++ b/java/org/apache/tomcat/websocket/PerMessageDeflate.java
@@ -329,9 +329,15 @@ public class PerMessageDeflate implements Transformation {
 ByteBuffer uncompressedPayload = uncompressedPart.getPayload();
 SendHandler uncompressedIntermediateHandler = 
uncompressedPart.getIntermediateHandler();
 
-deflater.setInput(uncompressedPayload.array(),
-uncompressedPayload.arrayOffset() + 
uncompressedPayload.position(),
-uncompressedPayload.remaining());
+if (uncompressedPayload.hasArray()) {
+deflater.setInput(uncompressedPayload.array(),
+uncompressedPayload.arrayOffset() + 
uncompressedPayload.position(),
+uncompressedPayload.remaining());
+} else {
+byte[] bytes = new byte[uncompressedPayload.remaining()];
+uncompressedPayload.get(bytes);
+deflater.setInput(bytes, 0, bytes.length);
+}
 
 int flush = (uncompressedPart.isFin() ? Deflater.SYNC_FLUSH : 
Deflater.NO_FLUSH);
 boolean deflateRequired = true;
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index f2e39daa88..1b1d5bc38c 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -121,6 +121,14 @@
   
 
   
+  
+
+  
+66575: Avoid unchecked use of the backing array of a
+buffer provided by the user in the compression transformation. (remm)
+  
+
+  
 
 
   


-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[tomcat] branch main updated: Avoid unchecked use of the backing array

2023-04-21 Thread remm
This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
 new 4d963f8c51 Avoid unchecked use of the backing array
4d963f8c51 is described below

commit 4d963f8c51cfc20abd983932f66c61d7d92026c5
Author: remm 
AuthorDate: Fri Apr 21 09:52:54 2023 +0200

Avoid unchecked use of the backing array

This comes from user code and can happen with a direct (bad idea ...) or
read only buffer. This will cause inefficient byte copying.
Also review all other uses of .array() in Tomcat, which all seem safe.
---
 java/org/apache/tomcat/websocket/PerMessageDeflate.java | 12 +---
 webapps/docs/changelog.xml  |  8 
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/java/org/apache/tomcat/websocket/PerMessageDeflate.java 
b/java/org/apache/tomcat/websocket/PerMessageDeflate.java
index 482c5c1d2d..665cfd24f4 100644
--- a/java/org/apache/tomcat/websocket/PerMessageDeflate.java
+++ b/java/org/apache/tomcat/websocket/PerMessageDeflate.java
@@ -329,9 +329,15 @@ public class PerMessageDeflate implements Transformation {
 ByteBuffer uncompressedPayload = uncompressedPart.getPayload();
 SendHandler uncompressedIntermediateHandler = 
uncompressedPart.getIntermediateHandler();
 
-deflater.setInput(uncompressedPayload.array(),
-uncompressedPayload.arrayOffset() + 
uncompressedPayload.position(),
-uncompressedPayload.remaining());
+if (uncompressedPayload.hasArray()) {
+deflater.setInput(uncompressedPayload.array(),
+uncompressedPayload.arrayOffset() + 
uncompressedPayload.position(),
+uncompressedPayload.remaining());
+} else {
+byte[] bytes = new byte[uncompressedPayload.remaining()];
+uncompressedPayload.get(bytes);
+deflater.setInput(bytes, 0, bytes.length);
+}
 
 int flush = (uncompressedPart.isFin() ? Deflater.SYNC_FLUSH : 
Deflater.NO_FLUSH);
 boolean deflateRequired = true;
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 8d738158f1..33ef668c09 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -121,6 +121,14 @@
   
 
   
+  
+
+  
+66575: Avoid unchecked use of the backing array of a
+buffer provided by the user in the compression transformation. (remm)
+  
+
+  
 
 
   


-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[Bug 66574] Deadlock in websocket code

2023-04-21 Thread bugzilla
https://bz.apache.org/bugzilla/show_bug.cgi?id=66574

--- Comment #4 from Boris Petrov  ---
Created attachment 38543
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=38543=edit
Thread dump

-- 
You are receiving this mail because:
You are the assignee for the bug.
-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[Bug 66574] Deadlock in websocket code

2023-04-21 Thread bugzilla
https://bz.apache.org/bugzilla/show_bug.cgi?id=66574

Boris Petrov  changed:

   What|Removed |Added

 Status|NEEDINFO|NEW

--- Comment #3 from Boris Petrov  ---
I used the word "deadlock" a bit loosely, yes, sorry. It's not exactly a
deadlock between these two threads but rather an issue that these two threads
are blocked and not continuing. Probably the same reason as the two linked
issues - `sendText` doesn't call the callback.

Is there really nothing in the changelog from 9.0.73 to 9.0.74 that could
possibly explain this change? As I said, it *never* happened on 73, on 74 it
happens often.

I've also attached a full threaddump. You can probably ignore the JRuby stuff -
that's what I run my tests with. Yesterday, when I also saw the issue in
production, there was no JRuby there. If a thread dump without JRuby is needed,
I could try to provide one.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[Bug 66531] Threading model causes deadlocks

2023-04-21 Thread bugzilla
https://bz.apache.org/bugzilla/show_bug.cgi?id=66531

Boris Petrov  changed:

   What|Removed |Added

 CC||boris_pet...@live.com

-- 
You are receiving this mail because:
You are the assignee for the bug.
-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



Re: sendfile and async?

2023-04-21 Thread Romain Manni-Bucau
The use case was something like:

* checkDocBaseUpToDate() // done async if the validity period is passed
(means each 5mn check wil be async else sync is ok)
* serve() // delegate

No error but the GET has the right content-length but content is empty
cause in async sendfile is not processed.

Le jeu. 20 avr. 2023 à 22:30, Christopher Schultz <
ch...@christopherschultz.net> a écrit :

> Rmoain,
>
> On 4/20/23 15:27, Romain Manni-Bucau wrote:
> > I just notice using nio connector+sendfile+asynccontext seems quite not
> > functional, is it intended?
>  >
> > My original intent was to add a kind of pre-hook to DefaultServlet which
> > was async (nio http client) so wanted to use asynccontext then delegate
> to
> > super.doGet (more or less) but I got this sendfile issue with such a
> mode.
> > Is it intended or just part of the code which didnt get enough love?
>
> Can you give a little more detail?
>
> You wanted to subclass DefaultServlet but delegate to super.doGet under
> some cases, right? Do you always enter async mode, then delegate? What
> error/failure do you get?
>
> -chris
>
> -
> To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: dev-h...@tomcat.apache.org
>
>