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 <r...@apache.org>
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