Skip to content

Commit

Permalink
Safely convert from uint64_t to size_t.
Browse files Browse the repository at this point in the history
This fixes #8.

Signed-off-by: Todd Malsbary <[email protected]>
  • Loading branch information
malsbat committed May 15, 2019
1 parent 2ee61af commit 4eb1bb9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion rmw_dps_cpp/include/rmw_dps_cpp/CborStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::size_t>::max()) {
throw std::runtime_error("array size too large");
}
*size = info;
return *this;
}

Expand Down

0 comments on commit 4eb1bb9

Please sign in to comment.