-
Notifications
You must be signed in to change notification settings - Fork 136
Handle ResponseAccumulator not being able to buffer large response in memory #637
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 Check content length header for early exit
e675f60 to
a9122e8
Compare
| public var maxBodySize: Int = maxByteBufferSize { | ||
| didSet { | ||
| precondition( | ||
| self.maxBodySize <= Self.maxByteBufferSize, |
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.
Relatively minor, but wouldn't it also make sense to verify that the new value isn't negative?
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.
Added in f0947e9
| switch self.state { | ||
| case .idle: | ||
| if let contentLength = head.headers.first(name: "Content-Length"), | ||
| let announcedBodySize = Int(contentLength), |
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.
Should we be tolerating the possibility of a non-integer Content-Length field here?
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.
That's at least what we do in swift-nio so far:
https://github.com/apple/swift-nio/blob/41f0b2d3983038ae68bbb902ea43e123a5466494/Sources/NIOHTTP1/HTTPTypes.swift#L1508
075241b to
986bb05
Compare
Motivation
If the response being buffered by the
ResponseAccumulatoris too large (larger thanUInt32.max), a crash will occur.Modifications
public var maxBodySize: IntonResponseAccumulatorResponseTooBigErrorif the response bodies size is larger thanmaxBodySizeResult
Will now fail graciously if too big a response is buffered in memory via the
ResponseAccumulator.In addition, a user can configure the max size themself.