mirror of
https://github.com/apple/swift-nio-extras
synced 2026-11-25 04:47:50 +00:00
1.8.0
* fix crash in LengthFieldBasedFrameDecoder for malicious length values Motivation: LengthFieldBasedFrameDecoder will cause a fatal error if the length value does not fit into an `Int`. This can happen if `lengthFieldLength` is set to `.eight` and we are on a 64 bit platform or if `lengthFieldLength` is set to `.four` and we are on a 32-bit platform. If we then receive a length field value which is greater than `Int.max` the conversion from `UInt` to `Int` will cause a fatal error. This could be abused to crash a server by only sending 4 or 8 bytes. Modifications: safely convert UInt64 & UInt32 to Int and throw an error if they can't be represented as an Int Result: - LengthFieldBasedFrameDecoder with lengthFieldLength set to `.eight` can no longer crash the server on a 64-bit platform - LengthFieldBasedFrameDecoder with lengthFieldLength set to `.four` can no longer crash the server on a 32-bit platform * use early exit instead of XCTSkipIf * add support for `.eight` on 32-bit platforms * limit frame length to `Int32.max` * change test names * throw correct error * fix compilation for Swift 5.0 and add NIO prefix to error enum * add test for maximum allowed length and one above the maximum allowed length Signed-off-by: David Nadoba <dnadoba@gmail.com> * run XCTest script Signed-off-by: David Nadoba <dnadoba@gmail.com> Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
NIOExtras
NIOExtras is a good place for code that is related to NIO but not core. It can also be used to incubate APIs for tasks that are possible with core-NIO but are cumbersome today.
What makes a good contribution to NIOExtras?
- a protocol encoder/decoder pair (also called "codec") that is often used but is small enough so it doesn't need its own repository
- a helper to achieve a task that is harder-than-necessary to achieve with core-NIO
Code Quality / Stability
All code will go through code review like in the other repositories related to the SwiftNIO project.
swift-nio-extras part of the SwiftNIO 2 family of repositories and depends on the following:
swift-nio, version 2.0.0 or better.- Swift 5.0.
zliband its development headers installed on the system. But don't worry, you'll findzlibon pretty much any UNIX system that can compile any sort of code.
To depend on swift-nio-extras, put the following in the dependencies of your Package.swift:
.package(url: "https://github.com/apple/swift-nio-extras.git", from: "1.0.0"),
Support for older Swift versions
On the nio-extras-0.1 branch, you can find the swift-nio-extras version for the SwiftNIO 1 family. It requires Swift 4.1 or better.
Current Contents
QuiescingHelper: Helps to quiesce a server by notifying user code when all previously open connections have closed.LineBasedFrameDecoderSplits incomingByteBuffers on line endings.FixedLengthFrameDecoderSplits incomingByteBuffers by a fixed number of bytes.LengthFieldBasedFrameDecoderSplits incomingByteBuffers by a number of bytes specified in a fixed length header contained within the buffer.LengthFieldPrependerPrepends the number of bytes to outgoingByteBuffers as a fixed length header. Can be used in a codec pair with theLengthFieldBasedFrameDecoder.RequestResponseHandlerMatches a request and a promise with the corresponding response.HTTPResponseCompressorCompresses the body of every HTTP/1 response message.DebugInboundsEventHandlerPrints out all inbound events that travel through theChannelPipeline.DebugOutboundsEventHandlerPrints out all outbound events that travel through theChannelPipeline.WritePCAPHandlerAChannelHandlerthat writes.pcapcontaining the traffic of theChannelPipelinethat you can inspect with Wireshark/tcpdump.
Description
Mirror of github.com/apple/swift-nio-extras
2.5 MiB
0 Stars
1 Watchers
0 Forks
Languages
Swift
52.7%
C
47%
Shell
0.3%