From 4eb1bb9f543728e7ca88db31fa5a774695856ea9 Mon Sep 17 00:00:00 2001 From: Todd Malsbary Date: Wed, 15 May 2019 16:35:22 -0400 Subject: [PATCH] Safely convert from uint64_t to size_t. This fixes #8. Signed-off-by: Todd Malsbary --- rmw_dps_cpp/include/rmw_dps_cpp/CborStream.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rmw_dps_cpp/include/rmw_dps_cpp/CborStream.hpp b/rmw_dps_cpp/include/rmw_dps_cpp/CborStream.hpp index c0c407a..f1d39c0 100644 --- a/rmw_dps_cpp/include/rmw_dps_cpp/CborStream.hpp +++ b/rmw_dps_cpp/include/rmw_dps_cpp/CborStream.hpp @@ -480,10 +480,15 @@ class RxStream inline RxStream & deserializeSequenceSize(size_t * size) { uint8_t maj; - DPS_Status ret = CBOR_Peek(&buffer_, &maj, size); + uint64_t info; + DPS_Status ret = CBOR_Peek(&buffer_, &maj, &info); if (ret != DPS_OK || (maj != CBOR_ARRAY && maj != CBOR_BYTES)) { throw std::runtime_error("failed to deserialize array size"); } + if (info > std::numeric_limits::max()) { + throw std::runtime_error("array size too large"); + } + *size = info; return *this; }