ros / ros_comm

ROS communications-related packages, including core client libraries (roscpp, rospy, roslisp) and graph introspection tools (rostopic, rosnode, rosservice, rosparam).
http://wiki.ros.org/ros_comm
764 stars 912 forks source link

Default constructed rosbag::ChunkedFile segfault on swap #2362

Closed Hugal31 closed 2 months ago

Hugal31 commented 12 months ago

rosbag::ChunkedFile::swap segfault if the ChunkedFile is default-constructed, because it tries to write to read_stream_->file_ while read_stream_ is null.

This causes rosbag::Bag to segfault as well when using std::swap, for instance when adding rosbags to a growing vector.

This code triggers the segfault:

#include <rosbag/bag.h>

int main()
{
  rosbag::Bag bag1;
  rosbag::Bag bag2;
  std::swap(bag1, bag2);
}