Skip to content
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

Infinite loop lead to OOM in WebSocket #435

Closed
yxztj opened this issue Dec 1, 2017 · 1 comment
Closed

Infinite loop lead to OOM in WebSocket #435

yxztj opened this issue Dec 1, 2017 · 1 comment

Comments

@yxztj
Copy link

yxztj commented Dec 1, 2017

In WebSocket.swift(near line 1248)

while !sOperation.isCancelled {
                let stream = s.stream
                let writeBuffer = UnsafeRawPointer(frame!.bytes+total).assumingMemoryBound(to: UInt8.self)
                let len = stream.write(data: Data(bytes: writeBuffer, count: offset-total))
                if len < 0 {
                    var error: Error?
                        let errCode = InternalErrorCode.outputStreamWriteError.rawValue
                        error = s.errorWithDetail("output stream error during write", code: errCode)
                    s.doDisconnect(error)
                    break
                } else {
                    total += len
                }

When the 'len' returned from stream.write is 0(inside write function, 0 is returned when outputStream is nil), therefore 'total' will not be increased, leading to infinite loop.

For a quick fix, is it OK to change the if statement 'len < 0' to 'len <= 0' so the loop would exit through error handling logic, to resolve the issue for now?

@daltoniam
Copy link
Owner

This has been added in version 3.0.3!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants