@@ -341,9 +341,9 @@ pcl::PCDReader::readHeader (std::istream &fs, pcl::PCLPointCloud2 &cloud,
341
341
342
342
if (nr_points == 0 )
343
343
{
344
- PCL_WARN (" [pcl::PCDReader::readHeader] No points to read \n " );
344
+ PCL_WARN (" [pcl::PCDReader::readHeader] number of points is zero. \n " );
345
345
}
346
-
346
+
347
347
// Compatibility with older PCD file versions
348
348
if (!width_read && !height_read)
349
349
{
@@ -557,6 +557,11 @@ pcl::PCDReader::readBodyBinary (const unsigned char *map, pcl::PCLPointCloud2 &c
557
557
}
558
558
559
559
auto data_size = static_cast <unsigned int > (cloud.data .size ());
560
+ if (data_size == 0 )
561
+ {
562
+ PCL_WARN (" [pcl::PCDReader::read] Binary compressed file has data size of zero.\n " );
563
+ return 0 ;
564
+ }
560
565
std::vector<char > buf (data_size);
561
566
// The size of the uncompressed data better be the same as what we stored in the header
562
567
unsigned int tmp_size = pcl::lzfDecompress (&map[data_idx + 8 ], compressed_size, buf.data (), data_size);
@@ -1369,42 +1374,43 @@ pcl::PCDWriter::writeBinaryCompressed (std::ostream &os, const pcl::PCLPointClou
1369
1374
return (-2 );
1370
1375
}
1371
1376
1372
- // ////////////////////////////////////////////////////////////////////
1373
- // Empty array holding only the valid data
1374
- // data_size = nr_points * point_size
1375
- // = nr_points * (sizeof_field_1 + sizeof_field_2 + ... sizeof_field_n)
1376
- // = sizeof_field_1 * nr_points + sizeof_field_2 * nr_points + ... sizeof_field_n * nr_points
1377
- std::vector<char > only_valid_data (data_size);
1378
-
1379
- // Convert the XYZRGBXYZRGB structure to XXYYZZRGBRGB to aid compression. For
1380
- // this, we need a vector of fields.size () (4 in this case), which points to
1381
- // each individual plane:
1382
- // pters[0] = &only_valid_data[offset_of_plane_x];
1383
- // pters[1] = &only_valid_data[offset_of_plane_y];
1384
- // pters[2] = &only_valid_data[offset_of_plane_z];
1385
- // pters[3] = &only_valid_data[offset_of_plane_RGB];
1386
- //
1387
- std::vector<char *> pters (fields.size ());
1388
- std::size_t toff = 0 ;
1389
- for (std::size_t i = 0 ; i < pters.size (); ++i)
1390
- {
1391
- pters[i] = &only_valid_data[toff];
1392
- toff += fields_sizes[i] * cloud.width * cloud.height ;
1393
- }
1377
+ std::vector<char > temp_buf (data_size * 3 / 2 + 8 );
1378
+ if (data_size != 0 ) {
1394
1379
1395
- // Go over all the points, and copy the data in the appropriate places
1396
- for (uindex_t i = 0 ; i < cloud.width * cloud.height ; ++i)
1397
- {
1398
- for (std::size_t j = 0 ; j < pters.size (); ++j)
1399
- {
1400
- memcpy (pters[j], &cloud.data [i * cloud.point_step + fields[j].offset ], fields_sizes[j]);
1401
- // Increment the pointer
1402
- pters[j] += fields_sizes[j];
1380
+ // ////////////////////////////////////////////////////////////////////
1381
+ // Empty array holding only the valid data
1382
+ // data_size = nr_points * point_size
1383
+ // = nr_points * (sizeof_field_1 + sizeof_field_2 + ... sizeof_field_n)
1384
+ // = sizeof_field_1 * nr_points + sizeof_field_2 * nr_points + ...
1385
+ // sizeof_field_n * nr_points
1386
+ std::vector<char > only_valid_data (data_size);
1387
+
1388
+ // Convert the XYZRGBXYZRGB structure to XXYYZZRGBRGB to aid compression. For
1389
+ // this, we need a vector of fields.size () (4 in this case), which points to
1390
+ // each individual plane:
1391
+ // pters[0] = &only_valid_data[offset_of_plane_x];
1392
+ // pters[1] = &only_valid_data[offset_of_plane_y];
1393
+ // pters[2] = &only_valid_data[offset_of_plane_z];
1394
+ // pters[3] = &only_valid_data[offset_of_plane_RGB];
1395
+ //
1396
+ std::vector<char *> pters (fields.size ());
1397
+ std::size_t toff = 0 ;
1398
+ for (std::size_t i = 0 ; i < pters.size (); ++i) {
1399
+ pters[i] = &only_valid_data[toff];
1400
+ toff += fields_sizes[i] * cloud.width * cloud.height ;
1401
+ }
1402
+
1403
+ // Go over all the points, and copy the data in the appropriate places
1404
+ for (uindex_t i = 0 ; i < cloud.width * cloud.height ; ++i) {
1405
+ for (std::size_t j = 0 ; j < pters.size (); ++j) {
1406
+ memcpy (pters[j],
1407
+ &cloud.data [i * cloud.point_step + fields[j].offset ],
1408
+ fields_sizes[j]);
1409
+ // Increment the pointer
1410
+ pters[j] += fields_sizes[j];
1411
+ }
1403
1412
}
1404
- }
1405
1413
1406
- std::vector<char > temp_buf (data_size * 3 / 2 + 8 );
1407
- if (data_size != 0 ) {
1408
1414
// Compress the valid data
1409
1415
unsigned int compressed_size = pcl::lzfCompress (&only_valid_data.front (),
1410
1416
static_cast <unsigned int > (data_size),
0 commit comments