Skip to content

Conversation

@gjcairo
Copy link
Collaborator

@gjcairo gjcairo commented Oct 4, 2022

Motivation

If the response being buffered by the ResponseAccumulator is too large (larger than UInt32.max), a crash will occur.

Modifications

  • Check that the number of bytes being written won't cause the buffer to go over the limit. If it does, return a failed future from didReceiveBodyPart(task:_:)
  • Created a new ResponseTooBigError to be used with the failed future.

Result

Will now fail graciously if too big a response is buffered in memory via the ResponseAccumulator.

… memory

## Motivation

If the response being buffered by the `ResponseAccumulator` is too large (larger than `UInt32.max`), a crash will occur.

## Modifications

* Check that the number of bytes being written won't cause the buffer to go over the limit. If it does, return a failed future from `didReceiveBodyPart(task:_:)`
* Created a new `ResponseTooBigError` to be used with the failed future.

## Result

Will now fail graciously if too big a response is buffered in memory via the `ResponseAccumulator`.
@swift-server-bot
Copy link

Can one of the admins verify this patch?

5 similar comments
@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@Lukasa Lukasa added the 🔨 semver/patch No public API change. label Oct 4, 2022
@Lukasa
Copy link
Collaborator

Lukasa commented Oct 5, 2022

@swift-server-bot add to allowlist

case .head(let head):
self.state = .body(head, part)
case .body(let head, var body):
if body.writerIndex + part.readableBytes > UInt32.max {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UInt32.max is a bit magic. I think the best solution would be to add a static property in swift-nio to ByteBuffer with the max size it can handle. But we can also just give this constant a descriptive name here and document it.

@dnadoba
Copy link
Collaborator

dnadoba commented Oct 7, 2022

closing in favor of #637

@dnadoba dnadoba closed this Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants