permessage_deflate 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0b7269ee5c2053e590df3ee23dee682643a94141
4
- data.tar.gz: ce977b261ba5a4496a18a295ba786e522ff7c54d
2
+ SHA256:
3
+ metadata.gz: 2947014b879c7bd9afe0c8eb0bb3b48bd5aa89012d6b80ab1413f4d77f50b27f
4
+ data.tar.gz: 4558f0fb7a4e1954f675654d151b63c6d7f16d8f2dadf3e5c392b6b1c0951503
5
5
  SHA512:
6
- metadata.gz: 5c5e3671daa908ef039e1d0ebc7adc7f216072b38f04f2f6668cd1b74acc5c81946233053002cbff5af045fc8454ab087a2bdc03d90e4dab9cf94bf5f57e1617
7
- data.tar.gz: d4b4e6f843ed4eef06eb7c5b16a1c322689c9f61bd662fc581c1101824011113674c3c6248f89e9ec798bb6895cd64a401eb0408ada92c634d81903dfe5e1424
6
+ metadata.gz: 9f7aa8d7ff53106a77ba388e8617008850dbc1ac36b2f0864927ac185d27f7e3a310e967b1cd974a5fabe46d818d0901c9c4ea438d8388cc3f3dc2fa2590c26e
7
+ data.tar.gz: c51480bb46fbbc174468b425c3a660e96e851938f04887712b060d711c12a52a7db43e632d022c05837f13222a9e496893e909ca05b2df6e90e289ab4aeca8cd
data/CHANGELOG.md CHANGED
@@ -1,21 +1,27 @@
1
+ ### 0.2.0 / 2026-11-16
2
+
3
+ - Implement the `max_length` option from `websocket-extensions` to limit the
4
+ size of decompressed messages
5
+ - Change license from MIT to Apache 2.0
6
+
1
7
  ### 0.1.4 / 2017-09-10
2
8
 
3
- * Use `9` instead of `8` as the `windowBits` parameter to zlib, to deal with
9
+ - Use `9` instead of `8` as the `windowBits` parameter to zlib, to deal with
4
10
  restrictions introduced in zlib v1.2.9
5
11
 
6
12
  ### 0.1.3 / 2016-05-20
7
13
 
8
- * Amend all warnings issued when running with -W2
14
+ - Amend all warnings issued when running with -W2
9
15
 
10
16
  ### 0.1.2 / 2015-11-06
11
17
 
12
- * The server does not send `server_max_window_bits` if the client does not ask
18
+ - The server does not send `server_max_window_bits` if the client does not ask
13
19
  for it; this works around an issue in Firefox.
14
20
 
15
21
  ### 0.1.1 / 2014-12-18
16
22
 
17
- * Don't allow configure() to be called with unrecognized options
23
+ - Don't allow configure() to be called with unrecognized options
18
24
 
19
25
  ### 0.1.0 / 2014-12-13
20
26
 
21
- * Initial release
27
+ - Initial release
data/LICENSE.md CHANGED
@@ -1,21 +1,12 @@
1
- # The MIT License
1
+ Copyright 2014-2026 James Coglan
2
2
 
3
- Copyright (c) 2014-2017 James Coglan
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4
+ this file except in compliance with the License. You may obtain a copy of the
5
+ License at
4
6
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of
6
- this software and associated documentation files (the 'Software'), to deal in
7
- the Software without restriction, including without limitation the rights to
8
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
- the Software, and to permit persons to whom the Software is furnished to do so,
10
- subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
+ http://www.apache.org/licenses/LICENSE-2.0
21
8
 
9
+ Unless required by applicable law or agreed to in writing, software distributed
10
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
12
+ specific language governing permissions and limitations under the License.
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
- # permessage_deflate [![Build status](https://secure.travis-ci.org/faye/permessage-deflate-ruby.svg)](http://travis-ci.org/faye/permessage-deflate-ruby)
1
+ # permessage_deflate
2
2
 
3
- Implements the
4
- [permessage-deflate](https://tools.ietf.org/html/draft-ietf-hybi-permessage-compression)
3
+ Implements the [permessage-deflate](https://tools.ietf.org/html/rfc7692)
5
4
  WebSocket protocol extension as a plugin for
6
5
  [websocket-extensions](https://github.com/faye/websocket-extensions-ruby).
7
6
 
@@ -44,24 +43,24 @@ the peer, and those that are negotiated as part of the protocol. The settings
44
43
  only affecting the compressor are described fully in the [Zlib
45
44
  documentation](http://ruby-doc.org/stdlib-2.1.0/libdoc/zlib/rdoc/Zlib/Deflate.html#method-c-new):
46
45
 
47
- * `:level`: sets the compression level, can be an integer from `0` to `9`, or
46
+ - `:level`: sets the compression level, can be an integer from `0` to `9`, or
48
47
  one of the constants `Zlib::NO_COMPRESSION`, `Zlib::BEST_SPEED`,
49
48
  `Zlib::BEST_COMPRESSION`, or `Zlib::DEFAULT_COMPRESSION`
50
- * `:mem_level`: sets how much memory the compressor allocates, can be an integer
49
+ - `:mem_level`: sets how much memory the compressor allocates, can be an integer
51
50
  from `1` to `9`, or one of the constants `Zlib::MAX_MEM_LEVEL`, or
52
51
  `Zlib::DEF_MEM_LEVEL`
53
- * `:strategy`: can be one of the constants `Zlib::FILTERED`,
52
+ - `:strategy`: can be one of the constants `Zlib::FILTERED`,
54
53
  `Zlib::HUFFMAN_ONLY`, `Zlib::RLE`, `Zlib::FIXED`, or `Zlib::DEFAULT_STRATEGY`
55
54
 
56
55
  The other options relate to settings that are negotiated via the protocol and
57
56
  can be used to set the local session's behaviour and control that of the peer:
58
57
 
59
- * `:no_context_takeover`: if `true`, stops the session reusing a deflate context
58
+ - `:no_context_takeover`: if `true`, stops the session reusing a deflate context
60
59
  between messages
61
- * `:request_no_context_takeover`: if `true`, makes the session tell the other
60
+ - `:request_no_context_takeover`: if `true`, makes the session tell the other
62
61
  peer not to reuse a deflate context between messages
63
- * `:max_window_bits`: an integer from `8` to `15` inclusive that sets the
62
+ - `:max_window_bits`: an integer from `8` to `15` inclusive that sets the
64
63
  maximum size of the session's sliding window; a lower window size will be used
65
64
  if requested by the peer
66
- * `:request_max_window_bits`: an integer from `8` to `15` inclusive to ask the
65
+ - `:request_max_window_bits`: an integer from `8` to `15` inclusive to ask the
67
66
  other peer to use to set its maximum sliding window size, if supported
@@ -11,8 +11,8 @@ class PermessageDeflate
11
11
  true
12
12
  end
13
13
 
14
- def initialize(options, params)
15
- super(options)
14
+ def initialize(options, session_opts, params)
15
+ super(options, session_opts)
16
16
  @params = params
17
17
  end
18
18
 
@@ -1,6 +1,15 @@
1
1
  class PermessageDeflate
2
2
  class Session
3
3
 
4
+ class SessionError < StandardError
5
+ attr_reader :type
6
+
7
+ def initialize(message, type)
8
+ super(message)
9
+ @type = type
10
+ end
11
+ end
12
+
4
13
  VALID_PARAMS = [
5
14
  'server_no_context_takeover',
6
15
  'client_no_context_takeover',
@@ -8,9 +17,11 @@ class PermessageDeflate
8
17
  'client_max_window_bits'
9
18
  ]
10
19
 
11
- MIN_WINDOW_BITS = 9
12
- MAX_WINDOW_BITS = 15
13
- VALID_WINDOW_BITS = [8, 9, 10, 11, 12, 13, 14, 15]
20
+ MIN_WINDOW_BITS = 9
21
+ MAX_WINDOW_BITS = 15
22
+ VALID_WINDOW_BITS = [8, 9, 10, 11, 12, 13, 14, 15]
23
+ DEFAULT_MAX_LENGTH = 0x3ffffff # 64 MB
24
+ RAW_TAIL_BYTES = [0x00, 0x00, 0xff, 0xff].pack('C*')
14
25
 
15
26
  def self.valid_params?(params)
16
27
  return false unless params.keys.all? { |k| VALID_PARAMS.include?(k) }
@@ -31,7 +42,7 @@ class PermessageDeflate
31
42
  true
32
43
  end
33
44
 
34
- def initialize(options)
45
+ def initialize(options, session_opts)
35
46
  @level = options.fetch(:level, Zlib::DEFAULT_COMPRESSION)
36
47
  @mem_level = options.fetch(:mem_level, Zlib::DEF_MEM_LEVEL)
37
48
  @strategy = options.fetch(:strategy, Zlib::DEFAULT_STRATEGY)
@@ -41,6 +52,8 @@ class PermessageDeflate
41
52
  @request_no_context_takeover = options.fetch(:request_no_context_takeover, false)
42
53
  @request_max_window_bits = options.fetch(:request_max_window_bits, nil)
43
54
 
55
+ @max_length = session_opts.fetch(:max_length, DEFAULT_MAX_LENGTH)
56
+
44
57
  @deflate = @inflate = nil
45
58
  end
46
59
 
@@ -48,9 +61,21 @@ class PermessageDeflate
48
61
  return message unless message.rsv1
49
62
 
50
63
  inflate = get_inflate
64
+ chunks = []
65
+ length = 0
66
+
67
+ inflate.inflate(message.data) do |chunk|
68
+ chunks << chunk
69
+ length += chunk.bytesize
70
+
71
+ if length > @max_length
72
+ free(inflate)
73
+ raise SessionError.new('WebSocket frame length too large after decompression', 1009)
74
+ end
75
+ end
51
76
 
52
- message.data = inflate.inflate(message.data) +
53
- inflate.inflate([0x00, 0x00, 0xff, 0xff].pack('C*'))
77
+ chunks << inflate.inflate(RAW_TAIL_BYTES)
78
+ message.data = chunks.join('')
54
79
 
55
80
  free(inflate) unless @inflate
56
81
  message
@@ -21,7 +21,7 @@ class PermessageDeflate
21
21
  def self.validate_options(options, valid_keys)
22
22
  options.keys.each do |key|
23
23
  unless valid_keys.include?(key)
24
- raise ConfigurationError, "Unrecognized option: #{key.inspect}"
24
+ raise ConfigurationError, "Unrecognized option: #{ key.inspect }"
25
25
  end
26
26
  end
27
27
  end
@@ -41,13 +41,13 @@ class PermessageDeflate
41
41
  PermessageDeflate.new(options)
42
42
  end
43
43
 
44
- def create_client_session
45
- ClientSession.new(@options || {})
44
+ def create_client_session(session_opts = {})
45
+ ClientSession.new(@options || {}, session_opts)
46
46
  end
47
47
 
48
- def create_server_session(offers)
48
+ def create_server_session(offers, session_opts = {})
49
49
  offers.each do |offer|
50
- return ServerSession.new(@options || {}, offer) if ServerSession.valid_params?(offer)
50
+ return ServerSession.new(@options || {}, session_opts, offer) if ServerSession.valid_params?(offer)
51
51
  end
52
52
  nil
53
53
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: permessage_deflate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Coglan
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2017-09-10 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rspec
@@ -24,7 +23,6 @@ dependencies:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
25
  version: '0'
27
- description:
28
26
  email: jcoglan@gmail.com
29
27
  executables: []
30
28
  extensions: []
@@ -38,11 +36,10 @@ files:
38
36
  - lib/permessage_deflate/client_session.rb
39
37
  - lib/permessage_deflate/server_session.rb
40
38
  - lib/permessage_deflate/session.rb
41
- homepage: http://github.com/faye/permessage-deflate-ruby
39
+ homepage: https://github.com/faye/permessage-deflate-ruby
42
40
  licenses:
43
- - MIT
41
+ - Apache-2.0
44
42
  metadata: {}
45
- post_install_message:
46
43
  rdoc_options:
47
44
  - "--main"
48
45
  - README.md
@@ -61,9 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
58
  - !ruby/object:Gem::Version
62
59
  version: '0'
63
60
  requirements: []
64
- rubyforge_project:
65
- rubygems_version: 2.6.11
66
- signing_key:
61
+ rubygems_version: 3.6.9
67
62
  specification_version: 4
68
63
  summary: Per-message DEFLATE compression extension for WebSocket connections
69
64
  test_files: []