diff options
author | Jakub Dudycz <jdudycz@nokia.com> | 2018-06-28 12:41:29 +0200 |
---|---|---|
committer | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-08-02 11:14:32 +0200 |
commit | f73d7f4c251aca719aa514641339226a2ee9d454 (patch) | |
tree | 17d38e63d3d6e1037c019920fe4ac6eeb604447c /hv-collector-domain/src/main | |
parent | 03702b48989174dc8afa855e663a28e34b4da67b (diff) |
Reject messages with payload size > 1MiB
- Update validation in WireFrameDecoder class
- Write unit and component tests for that case
Closes ONAP-340
Change-Id: I68cb608fd76118719b12a83de1ef930160f8a162
Signed-off-by: Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
Issue-ID: DCAEGEN2-601
Diffstat (limited to 'hv-collector-domain/src/main')
-rw-r--r-- | hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/codec.kt | 13 | ||||
-rw-r--r-- | hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/errors.kt | 3 |
2 files changed, 14 insertions, 2 deletions
diff --git a/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/codec.kt b/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/codec.kt index 22767ed3..39841d6a 100644 --- a/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/codec.kt +++ b/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/codec.kt @@ -52,9 +52,9 @@ class WireFrameDecoder { fun decodeFirst(byteBuf: ByteBuf): Either<WireFrameDecodingError, WireFrame> = when { - isEmpty(byteBuf) -> Left(EmptyWireFrame) + isEmpty(byteBuf) -> Left(EmptyWireFrame) headerDoesNotFit(byteBuf) -> Left(MissingWireFrameHeaderBytes) - else -> parseFrame(byteBuf) + else -> parseFrame(byteBuf) } private fun headerDoesNotFit(byteBuf: ByteBuf) = byteBuf.readableBytes() < WireFrame.HEADER_SIZE @@ -74,6 +74,11 @@ class WireFrameDecoder { val payloadTypeRaw = byteBuf.readUnsignedByte() val payloadSize = byteBuf.readInt() + + if (payloadSize > MAX_PAYLOAD_SIZE) { + return Left(PayloadSizeExceeded) + } + if (byteBuf.readableBytes() < payloadSize) { byteBuf.resetReaderIndex() return Left(MissingWireFramePayloadBytes) @@ -83,4 +88,8 @@ class WireFrameDecoder { return Right(WireFrame(payload, version, payloadTypeRaw, payloadSize)) } + + companion object { + const val MAX_PAYLOAD_SIZE = 1024 * 1024 + } } diff --git a/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/errors.kt b/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/errors.kt index fb225202..626bf329 100644 --- a/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/errors.kt +++ b/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/errors.kt @@ -19,6 +19,8 @@ */ package org.onap.dcae.collectors.veshv.domain +import org.onap.dcae.collectors.veshv.domain.WireFrameDecoder.Companion.MAX_PAYLOAD_SIZE + /** * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com> * @since June 2018 @@ -35,6 +37,7 @@ class InvalidWireFrameMarker(actualMarker: Short) : InvalidWireFrame( "Invalid start of frame. Expected 0x%02X, but was 0x%02X".format(WireFrame.MARKER_BYTE, actualMarker)) +object PayloadSizeExceeded : InvalidWireFrame("payload size exceeds the limit ($MAX_PAYLOAD_SIZE bytes)") // Missing bytes errors |