Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2015-12-07 20:15:29 +0000
committerJoakim Erdfelt2015-12-07 20:15:29 +0000
commitb9c15355520f1c0db9ddf4fa0d237b68269438b5 (patch)
tree470ee4524d7da188ac5a1805b573c858d3b69f16 /jetty-websocket/websocket-common
parentbae11382115bca0ef8bcfcaf03eb95586e085488 (diff)
downloadorg.eclipse.jetty.project-b9c15355520f1c0db9ddf4fa0d237b68269438b5.tar.gz
org.eclipse.jetty.project-b9c15355520f1c0db9ddf4fa0d237b68269438b5.tar.xz
org.eclipse.jetty.project-b9c15355520f1c0db9ddf4fa0d237b68269438b5.zip
481567 - permessage-deflate causing data-dependent ju.zip.DataFormatException: invalid stored block lengths
+ Reworked PerMessageDeflateExtensionTest to test with different modes (http/ws vs https/wss), different messages sizes, and input buffer sizes (these various configurations do trigger the reported bug) + Made CompressExtension loop over the input buffer if the buffer happens to not be entirely consumed.
Diffstat (limited to 'jetty-websocket/websocket-common')
-rw-r--r--jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/CompressExtension.java39
-rw-r--r--jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/util/Sha1Sum.java110
2 files changed, 131 insertions, 18 deletions
diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/CompressExtension.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/CompressExtension.java
index 5c27104c59..ec73e3c384 100644
--- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/CompressExtension.java
+++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/CompressExtension.java
@@ -154,30 +154,33 @@ public abstract class CompressExtension extends AbstractExtension
return;
}
byte[] output = new byte[DECOMPRESS_BUF_SIZE];
-
- if (inflater.needsInput() && !supplyInput(inflater,buf))
- {
- LOG.debug("Needed input, but no buffer could supply input");
- return;
- }
-
- int read = 0;
- while ((read = inflater.inflate(output)) >= 0)
+
+ while(buf.hasRemaining() && inflater.needsInput())
{
- if (read == 0)
+ if (!supplyInput(inflater,buf))
{
- LOG.debug("Decompress: read 0 {}",toDetail(inflater));
- break;
+ LOG.debug("Needed input, but no buffer could supply input");
+ return;
}
- else
+
+ int read = 0;
+ while ((read = inflater.inflate(output)) >= 0)
{
- // do something with output
- if (LOG.isDebugEnabled())
+ if (read == 0)
{
- LOG.debug("Decompressed {} bytes: {}",read,toDetail(inflater));
+ LOG.debug("Decompress: read 0 {}",toDetail(inflater));
+ break;
+ }
+ else
+ {
+ // do something with output
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Decompressed {} bytes: {}",read,toDetail(inflater));
+ }
+
+ accumulator.copyChunk(output,0,read);
}
-
- accumulator.copyChunk(output,0,read);
}
}
diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/util/Sha1Sum.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/util/Sha1Sum.java
new file mode 100644
index 0000000000..f3771efb8a
--- /dev/null
+++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/util/Sha1Sum.java
@@ -0,0 +1,110 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.websocket.common.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
+import java.security.DigestOutputStream;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.jetty.toolchain.test.IO;
+import org.junit.Assert;
+
+/**
+ * Calculate the sha1sum for various content
+ */
+public class Sha1Sum
+{
+ private static class NoOpOutputStream extends OutputStream
+ {
+ @Override
+ public void write(byte[] b) throws IOException
+ {
+ }
+
+ @Override
+ public void write(byte[] b, int off, int len) throws IOException
+ {
+ }
+
+ @Override
+ public void flush() throws IOException
+ {
+ }
+
+ @Override
+ public void close() throws IOException
+ {
+ }
+
+ @Override
+ public void write(int b) throws IOException
+ {
+ }
+ }
+
+ public static String calculate(File file) throws NoSuchAlgorithmException, IOException
+ {
+ return calculate(file.toPath());
+ }
+
+ public static String calculate(Path path) throws NoSuchAlgorithmException, IOException
+ {
+ MessageDigest digest = MessageDigest.getInstance("SHA1");
+ try (InputStream in = Files.newInputStream(path,StandardOpenOption.READ);
+ NoOpOutputStream noop = new NoOpOutputStream();
+ DigestOutputStream digester = new DigestOutputStream(noop,digest))
+ {
+ IO.copy(in,digester);
+ return Hex.asHex(digest.digest());
+ }
+ }
+
+ public static String calculate(byte[] buf) throws NoSuchAlgorithmException
+ {
+ MessageDigest digest = MessageDigest.getInstance("SHA1");
+ digest.update(buf);
+ return Hex.asHex(digest.digest());
+ }
+
+ public static String calculate(byte[] buf, int offset, int len) throws NoSuchAlgorithmException
+ {
+ MessageDigest digest = MessageDigest.getInstance("SHA1");
+ digest.update(buf,offset,len);
+ return Hex.asHex(digest.digest());
+ }
+
+ public static String loadSha1(File sha1File) throws IOException
+ {
+ String contents = IO.readToString(sha1File);
+ Pattern pat = Pattern.compile("^[0-9A-Fa-f]*");
+ Matcher mat = pat.matcher(contents);
+ Assert.assertTrue("Should have found HEX code in SHA1 file: " + sha1File,mat.find());
+ return mat.group();
+ }
+
+}

Back to the top