aws-eventstream 1.4.0 → 1.4.1

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
2
  SHA256:
3
- metadata.gz: bd62e87a3b7eee5d16898a4020991b35a58bd8fa578cdc1af4bff0c22e2ede9d
4
- data.tar.gz: c9edd876524c36d92e99eaf670ef895f50ddadf464a679f07542970347d72e65
3
+ metadata.gz: ab51070b934f6cc24b6221b958d85de7e6385b00e1807c439ffb2c1c724d024b
4
+ data.tar.gz: 7768dae84ea125d169529dffe424543493d10a3555176f2c47a60d193633849a
5
5
  SHA512:
6
- metadata.gz: 1f419f5891fdf0d400e84b9d1cb998cf78506c42e8572e907c9e30eea9dd9e7f2b1f2d01313892c590531f953dfe2a19d62fd8f35aec5b9f22ceb7d1631ff36b
7
- data.tar.gz: aa83514fbe8ba5a2b93e77e7a26094ee0addb913dc2d2d8022ec6988658f28433398232a889b1b50ab1fc6d37e1befc8aa44d0442cc4a042fc63a65ed6be6510
6
+ metadata.gz: d5d7379e1df312197bd26c0790052645830901171a1c39a4602b41cf573cac527399e77452d5c33b9d8f9c5d2a458fce20500a8ed8a6f56611f2775bd1729594
7
+ data.tar.gz: f69606e1b8880d6d52085cc13164b2fe7856cbe4f2b994db6a347b7b8201e62a58904de2514467759b45fe7491ea7bcb5d6b42ae746bb40afeca7b4c523cb464
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  Unreleased Changes
2
2
  ------------------
3
3
 
4
+ 1.4.1 (2026-10-21)
5
+ ------------------
6
+
7
+ * Issue - Raise an error when event stream header names or values exceed supported byte-length limits.
8
+ * Issue - Raise an error when a fixed-width event stream header value does not fit its type's width.
9
+
4
10
  1.4.0 (2025-06-02)
5
11
  ------------------
6
12
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.0
1
+ 1.4.1
@@ -41,6 +41,14 @@ module Aws
41
41
  # and 4 bytes total message crc checksum
42
42
  OVERHEAD_LENGTH = 16
43
43
 
44
+ # Maximum encoded length of a single header name (1-byte unsigned length field)
45
+ MAX_HEADER_NAME_LENGTH = 255
46
+
47
+ # Maximum encoded length of a string/bytes header value. The length field is two bytes
48
+ # (and could hold 65,535), but the protocol caps the value at the signed 16-bit maximum
49
+ # (INT16_MAX, 2**15 - 1), so the encoder must enforce the lower limit.
50
+ MAX_HEADER_VALUE_LENGTH = 32_767
51
+
44
52
  # Maximum header length allowed (after encode) 128kb
45
53
  MAX_HEADERS_LENGTH = 1024 * 128
46
54
 
@@ -109,6 +117,9 @@ module Aws
109
117
  # @return [String]
110
118
  def encode_headers(message)
111
119
  header_entries = message.headers.map do |key, value|
120
+ if key.bytesize > MAX_HEADER_NAME_LENGTH
121
+ raise Aws::EventStream::Errors::EventHeaderNameLengthExceedError.new
122
+ end
112
123
  encoded_key = [key.bytesize, key].pack('Ca*')
113
124
 
114
125
  # header value
@@ -116,7 +127,15 @@ module Aws
116
127
  encoded_value = [type_index].pack('C')
117
128
  # boolean types doesn't need to specify value
118
129
  next [encoded_key, encoded_value].pack('a*a*') if !!pattern == pattern
119
- encoded_value = [encoded_value, value.value.bytesize].pack('a*S>') unless value_length
130
+ validate_fixed_width_value!(value, value_length) if value_length
131
+ unless value_length
132
+ # string and bytes types carry a 2-byte length prefix capped at INT16_MAX; reject
133
+ # oversized values rather than letting bytesize wrap mod 65536.
134
+ if value.value.bytesize > MAX_HEADER_VALUE_LENGTH
135
+ raise Aws::EventStream::Errors::EventHeaderValueLengthExceedError.new
136
+ end
137
+ encoded_value = [encoded_value, value.value.bytesize].pack('a*S>')
138
+ end
120
139
 
121
140
  [
122
141
  encoded_key,
@@ -132,6 +151,25 @@ module Aws
132
151
 
133
152
  private
134
153
 
154
+ # Fixed-width values carry no length prefix, so a value that does not fit its
155
+ # protocol width would either be silently truncated by #pack (integers) or
156
+ # misalign the header block (uuid). Reject both before anything is written.
157
+ def validate_fixed_width_value!(value, width)
158
+ v = value.value
159
+ valid =
160
+ if value.type == 'uuid'
161
+ v.respond_to?(:bytesize) && v.bytesize == width
162
+ elsif v.is_a?(Integer)
163
+ limit = 1 << (width * 8 - 1)
164
+ v >= -limit && v < limit
165
+ else
166
+ true
167
+ end
168
+ return if valid
169
+
170
+ raise Aws::EventStream::Errors::EventHeaderValueWidthError.new(value.type)
171
+ end
172
+
135
173
  def encode_prelude(total_length, headers_length)
136
174
  prelude_body = [total_length, headers_length].pack('NN')
137
175
  checksum = Zlib.crc32(prelude_body)
@@ -44,6 +44,27 @@ module Aws
44
44
  end
45
45
  end
46
46
 
47
+ # Raised when an encoded header name exceeds the 255-byte protocol limit
48
+ class EventHeaderNameLengthExceedError < RuntimeError
49
+ def initialize(*args)
50
+ super("Encoded header name length should be under 256 bytes.")
51
+ end
52
+ end
53
+
54
+ # Raised when an encoded header value exceeds the 32767-byte (INT16_MAX) protocol limit
55
+ class EventHeaderValueLengthExceedError < RuntimeError
56
+ def initialize(*args)
57
+ super("Encoded header value length should be under 32768 bytes.")
58
+ end
59
+ end
60
+
61
+ # Raised when a fixed-width header value does not fit its protocol width
62
+ class EventHeaderValueWidthError < RuntimeError
63
+ def initialize(type = nil, *args)
64
+ super("Header value does not fit the fixed width of header type '#{type}'.")
65
+ end
66
+ end
67
+
47
68
  end
48
69
  end
49
70
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-eventstream
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amazon Web Services