From 369ad578281eaf0a4c80511bb1af8b26f1b6583c Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Thu, 17 Dec 2009 07:26:05 +0000 Subject: Expand compression buffers if needed for JZlib git-svn-id: https://connectbot.googlecode.com/svn/trunk/connectbot@439 df292f66-193f-0410-a5fc-6d59da041ff2 --- AndroidManifest.xml | 2 +- src/com/trilead/ssh2/compression/Zlib.java | 61 ++++++++++++---------- .../ssh2/transport/TransportConnection.java | 3 +- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 0441e52..461570c 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -2,7 +2,7 @@ + android:versionCode="218"> deflate_tmpbuf.length) { + deflate_tmpbuf = new byte[buf.length + 1024]; + } + + deflate.next_out = deflate_tmpbuf; + deflate.next_out_index = 0; + deflate.avail_out = output.length; + + if (deflate.deflate(JZlib.Z_PARTIAL_FLUSH) != JZlib.Z_OK) { + System.err.println("compress: compression failure"); + } + + if (deflate.avail_in > 0) { + System.err.println("compress: deflated data too large"); + } + + int outputlen = output.length - deflate.avail_out; + + System.arraycopy(deflate_tmpbuf, 0, output, 0, outputlen); - do { - deflate.next_out = deflate_tmpbuf; - deflate.next_out_index = 0; - deflate.avail_out = BUF_SIZE; - status = deflate.deflate(JZlib.Z_PARTIAL_FLUSH); - switch (status) { - case JZlib.Z_OK: - System.arraycopy(deflate_tmpbuf, 0, output, outputlen, BUF_SIZE - - deflate.avail_out); - outputlen += (BUF_SIZE - deflate.avail_out); - break; - default: - System.err.println("compress: deflate returnd " + status); - } - } while (deflate.avail_out == 0); return outputlen; } @@ -84,20 +89,20 @@ public class Zlib implements ICompressor { while (true) { inflate.next_out = inflate_tmpbuf; inflate.next_out_index = 0; - inflate.avail_out = BUF_SIZE; + inflate.avail_out = DEFAULT_BUF_SIZE; int status = inflate.inflate(JZlib.Z_PARTIAL_FLUSH); switch (status) { case JZlib.Z_OK: - if (inflated_buf.length < inflated_end + BUF_SIZE + if (inflated_buf.length < inflated_end + DEFAULT_BUF_SIZE - inflate.avail_out) { - byte[] foo = new byte[inflated_end + BUF_SIZE + byte[] foo = new byte[inflated_end + DEFAULT_BUF_SIZE - inflate.avail_out]; System.arraycopy(inflated_buf, 0, foo, 0, inflated_end); inflated_buf = foo; } System.arraycopy(inflate_tmpbuf, 0, inflated_buf, inflated_end, - BUF_SIZE - inflate.avail_out); - inflated_end += (BUF_SIZE - inflate.avail_out); + DEFAULT_BUF_SIZE - inflate.avail_out); + inflated_end += (DEFAULT_BUF_SIZE - inflate.avail_out); length[0] = inflated_end; break; case JZlib.Z_BUF_ERROR: diff --git a/src/com/trilead/ssh2/transport/TransportConnection.java b/src/com/trilead/ssh2/transport/TransportConnection.java index 2384773..77eaded 100644 --- a/src/com/trilead/ssh2/transport/TransportConnection.java +++ b/src/com/trilead/ssh2/transport/TransportConnection.java @@ -152,8 +152,9 @@ public class TransportConnection else if (padd > 64) padd = 64; - // TODO add compression somewhere here if (send_comp != null && can_compress) { + if (send_comp_buffer.length < message.length + 1024) + send_comp_buffer = new byte[message.length + 1024]; len = send_comp.compress(message, off, len, send_comp_buffer); message = send_comp_buffer; } -- cgit v1.2.3