Skip to content

Commit

Permalink
Safely use data
Browse files Browse the repository at this point in the history
  • Loading branch information
0xTim committed Apr 18, 2023
1 parent 1b7f651 commit 1ff50ee
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Sources/Vapor/Request/Request+BodyStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ extension Request {
// See https://github.com/vapor/vapor/issues/2906
return eventLoop.flatSubmit {
let promise = eventLoop.makePromise(of: ByteBuffer.self)
var data = self.allocator.buffer(capacity: 0)
let data = NIOLoopBoundBox(self.allocator.buffer(capacity: 0), eventLoop: eventLoop)
self.read { chunk, next in
switch chunk {
case .buffer(var buffer):
if let max = max, data.readableBytes + buffer.readableBytes >= max {
if let max = max, data.value.readableBytes + buffer.readableBytes >= max {
promise.fail(Abort(.payloadTooLarge))
} else {
data.writeBuffer(&buffer)
data.value.writeBuffer(&buffer)
}
case .error(let error): promise.fail(error)
case .end: promise.succeed(data)
case .end: promise.succeed(data.value)
}
next?.succeed(())
}
Expand Down

0 comments on commit 1ff50ee

Please sign in to comment.