Skip to content

Commit 27cfbc7

Browse files
committed
Remove all event stream length validations
1 parent ad4d2a3 commit 27cfbc7

File tree

2 files changed

+1
-12
lines changed
  • runtime/protocol/aws-event-stream/common/src/aws/smithy/kotlin/runtime/awsprotocol/eventstream

2 files changed

+1
-12
lines changed

runtime/protocol/aws-event-stream/common/src/aws/smithy/kotlin/runtime/awsprotocol/eventstream/Message.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,9 @@ import aws.smithy.kotlin.runtime.text.encoding.encodeToHex
1212

1313
internal const val MESSAGE_CRC_BYTE_LEN = 4
1414

15-
// max message size is 16 MB
16-
internal const val MAX_MESSAGE_SIZE = 16 * 1024 * 1024
17-
18-
// max header size is 128 KB
19-
internal const val MAX_HEADER_SIZE = 128 * 1024
20-
2115
/*
2216
Message Wire Format
23-
See also: https://docs.aws.amazon.com/transcribe/latest/dg/event-stream-med.html
17+
See also: https://docs.aws.amazon.com/transcribe/latest/dg/streaming-setting-up.html
2418
2519
+--------------------------------------------------------------------+ --
2620
| Total Len (32) | |
@@ -49,7 +43,6 @@ public data class Message(val headers: List<Header>, val payload: ByteArray) {
4943
*/
5044
public fun decode(source: SdkBufferedSource): Message {
5145
val totalLen = source.peek().use { it.readInt().toUInt() }
52-
check(totalLen <= MAX_MESSAGE_SIZE.toUInt()) { "Invalid Message size: $totalLen" }
5346

5447
// Limiting the amount of data read by SdkBufferedSource is tricky and cause incorrect CRC
5548
// if not careful (e.g. creating a buffered source of a HashingSource will usually lead to incorrect results
@@ -117,8 +110,6 @@ public data class Message(val headers: List<Header>, val payload: ByteArray) {
117110
val payloadLen = payload.size
118111

119112
val messageLen = PRELUDE_BYTE_LEN_WITH_CRC + headersLen + payloadLen + MESSAGE_CRC_BYTE_LEN
120-
check(headersLen < MAX_HEADER_SIZE) { "Invalid Headers length: $headersLen" }
121-
check(messageLen < MAX_MESSAGE_SIZE) { "Invalid Message length: $messageLen" }
122113

123114
val prelude = Prelude(messageLen.toInt(), headersLen.toInt())
124115

runtime/protocol/aws-event-stream/common/src/aws/smithy/kotlin/runtime/awsprotocol/eventstream/Prelude.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ public data class Prelude(val totalLen: Int, val headersLength: Int) {
5656
val totalLen = buffer.readInt()
5757
val headerLen = buffer.readInt()
5858

59-
check(totalLen <= MAX_MESSAGE_SIZE) { "Invalid Message size: $totalLen" }
60-
check(headerLen <= MAX_HEADER_SIZE) { "Invalid Header size: $headerLen" }
6159
check(expectedCrc.contentEquals(computedCrc)) {
6260
"Prelude checksum mismatch; expected=0x${expectedCrc.encodeToHex()}; calculated=0x${computedCrc.encodeToHex()}"
6361
}

0 commit comments

Comments
 (0)