Skip to content

Commit

Permalink
Merge pull request #2125 from SergioRAgostinho/pcl_bus_error
Browse files Browse the repository at this point in the history
Prevent mmapping more than the original PCD file size
  • Loading branch information
taketwo authored Dec 8, 2017
2 parents e8cae92 + 7373e61 commit c57e1db
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion io/src/pcd_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,10 @@ pcl::PCDReader::read (const std::string &file_name, pcl::PCLPointCloud2 &cloud,
PCL_ERROR ("[pcl::PCDReader::read] Failure to open file %s\n", file_name.c_str () );
return (-1);
}

// Infer file size
const size_t file_size = pcl_lseek (fd, 0, SEEK_END);
pcl_lseek (fd, 0, SEEK_SET);

size_t mmap_size = offset + data_idx; // ...because we mmap from the start of the file.
if (data_type == 2)
Expand All @@ -767,7 +771,7 @@ pcl::PCDReader::read (const std::string &file_name, pcl::PCLPointCloud2 &cloud,
{
pcl_close (fd);
PCL_ERROR ("[pcl::PCDReader::read] read errno: %d strerror: %s\n", errno, strerror (errno));
PCL_ERROR ("[pcl::PCDReader::read] Error during road()!\n");
PCL_ERROR ("[pcl::PCDReader::read] Error during read()!\n");
return (-1);
}
mmap_size += compressed_size;
Expand All @@ -780,6 +784,13 @@ pcl::PCDReader::read (const std::string &file_name, pcl::PCLPointCloud2 &cloud,
mmap_size += cloud.data.size ();
}

if (mmap_size > file_size)
{
pcl_close (fd);
PCL_ERROR ("[pcl::PCDReader::read] Corrupted PCD file. The file is smaller than expected!\n");
return (-1);
}

// Prepare the map
#ifdef _WIN32
// As we don't know the real size of data (compressed or not),
Expand Down

0 comments on commit c57e1db

Please sign in to comment.