Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions rosidl_typesupport_fastrtps_c/resource/msg__type_support_c.cpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,16 @@ else:
uint32_t cdrSize;
cdr >> cdrSize;
size_t size = static_cast<size_t>(cdrSize);

// Check there are at least 'size' remaining bytes in the CDR stream before resizing
auto old_state = cdr.get_state();
bool correct_size = cdr.jump(size);
cdr.set_state(old_state);
if (!correct_size) {
fprintf(stderr, "sequence size exceeds remaining buffer\n");
return false;
}

if (ros_message->@(member.name).data) {
@(array_fini)(&ros_message->@(member.name));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,16 @@ cdr_deserialize(
uint32_t cdrSize;
cdr >> cdrSize;
size_t size = static_cast<size_t>(cdrSize);

// Check there are at least 'size' remaining bytes in the CDR stream before resizing
auto old_state = cdr.get_state();
bool correct_size = cdr.jump(size);
cdr.set_state(old_state);
if (!correct_size) {
fprintf(stderr, "sequence size exceeds remaining buffer\n");
return false;
}

ros_message.@(member.name).resize(size);
@[ if isinstance(member.type.value_type, BasicType) and member.type.value_type.typename not in ('boolean', 'wchar')]@
if (size > 0) {
Expand Down Expand Up @@ -296,7 +306,7 @@ cdr_deserialize(

@[end for]@
return true;
}
} // NOLINT(readability/fn_size)

@{

Expand Down