-
Notifications
You must be signed in to change notification settings - Fork 125
Handle ResponseAccumulator not being able to buffer large response in memory #631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… 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`.
Can one of the admins verify this patch? |
5 similar comments
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
@swift-server-bot add to allowlist |
@@ -397,6 +403,10 @@ public class ResponseAccumulator: HTTPClientResponseDelegate { | |||
case .head(let head): | |||
self.state = .body(head, part) | |||
case .body(let head, var body): | |||
if body.writerIndex + part.readableBytes > UInt32.max { |
There was a problem hiding this comment.
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.
closing in favor of #637 |
Motivation
If the response being buffered by the
ResponseAccumulator
is too large (larger thanUInt32.max
), a crash will occur.Modifications
didReceiveBodyPart(task:_:)
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
.