Skip to content

Commit

Permalink
fixed bug in Mojo::Transaction::WebSocket that prevented decompressio…
Browse files Browse the repository at this point in the history
…n errors from being handled gracefully
  • Loading branch information
kraih committed Jan 28, 2014
1 parent 2b20041 commit 3cd31a2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,5 +1,7 @@

4.72 2014-01-29
- Fixed bug in Mojo::Transaction::WebSocket that prevented decompression
errors from being handled gracefully.

4.71 2014-01-28
- Fixed a few compression bugs in Mojo::Transaction::WebSocket and
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/Transaction/WebSocket.pm
@@ -1,7 +1,7 @@
package Mojo::Transaction::WebSocket;
use Mojo::Base 'Mojo::Transaction';

use Compress::Raw::Zlib qw(Z_OK Z_SYNC_FLUSH);
use Compress::Raw::Zlib 'Z_SYNC_FLUSH';
use Config;
use Mojo::JSON;
use Mojo::Transaction::HTTP;
Expand Down Expand Up @@ -326,8 +326,8 @@ sub _message {
WindowBits => -15
);
$self->{inflate} = $inflate if $self->context_takeover;
return $self->finish(1009)
if $inflate->inflate(\($msg .= "\x00\x00\xff\xff"), my $out) != Z_OK;
$inflate->inflate(\($msg .= "\x00\x00\xff\xff"), my $out);
return $self->finish(1009) if length $msg;
$msg = $out;
}

Expand Down
5 changes: 5 additions & 0 deletions t/mojolicious/websocket_lite_app.t
Expand Up @@ -182,6 +182,11 @@ $t->message_ok->message_is({binary => 'a' x 50000});
ok length $payload < 262145, 'message has been compressed';
$t->finish_ok->finished_ok(1005);

# Compressed message exceeding the limit when uncompressed
$t->websocket_ok('/echo')
->header_is('Sec-WebSocket-Extensions' => 'permessage-deflate')
->send_ok({binary => 'a' x 1000000})->finished_ok(1009);

# Binary message in two 64bit frames without FIN bit (too large)
$t->websocket_ok('/echo')->send_ok([0, 0, 0, 0, 2, 'c' x 100000])
->send_ok([0, 0, 0, 0, 0, 'c' x 162146])->finished_ok(1009);
Expand Down

0 comments on commit 3cd31a2

Please sign in to comment.