Skip to content

Commit

Permalink
Add image size check to textured marker plugin to prevent crashes. (#613
Browse files Browse the repository at this point in the history
)

* Add image size check to textured marker plugin to prevent crashes.
  • Loading branch information
matt-attack authored and pjreed committed Feb 13, 2019
1 parent efc59a3 commit 8683b6d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mapviz_plugins/src/textured_marker_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,23 +262,34 @@ namespace mapviz_plugins

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

size_t bpp = 0;
if (markerData.encoding_ == sensor_msgs::image_encodings::BGRA8)
{
bpp = 4;
markerData.texture_.resize(static_cast<size_t>(markerData.texture_size_ * markerData.texture_size_ * 4));
}
else if (markerData.encoding_ == sensor_msgs::image_encodings::BGR8)
{
bpp = 3;
markerData.texture_.resize(static_cast<size_t>(markerData.texture_size_ * markerData.texture_size_ * 3));
}
else if (markerData.encoding_ == sensor_msgs::image_encodings::MONO8)
{
bpp = 1;
markerData.texture_.resize(static_cast<size_t>(markerData.texture_size_ * markerData.texture_size_));
}
else
{
ROS_WARN("Unsupported encoding: %s", markerData.encoding_.c_str());
}

size_t expected = marker.image.height*marker.image.width*bpp;
if (markerData.texture_.size() > 0 && marker.image.data.size() < expected)
{
ROS_ERROR("TexturedMarker image had expected data size %i but only got %i. Dropping message.", expected, marker.image.data.size());
return;
}

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

Expand Down

0 comments on commit 8683b6d

Please sign in to comment.