Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading PLY file produces segmentation fault #675

Closed
VictorLamoine opened this issue May 16, 2014 · 7 comments
Closed

Reading PLY file produces segmentation fault #675

VictorLamoine opened this issue May 16, 2014 · 7 comments
Labels
kind: bug Type of issue

Comments

@VictorLamoine
Copy link
Contributor

Some PLY files cannot be loaded and the PLYReader produces a segmentation fault.

Test code

#include <pcl/io/ply_io.h>

int
main (int argc, char *argv[])
{
  if (argc < 2)
    return (-1);

  pcl::PointCloud<pcl::PointXYZRGBA> cloud;

  int rvalue;
  rvalue = pcl::io::loadPLYFile (argv[1], cloud);
  printf ("loadPLYFile = %d\n", rvalue);

  if (rvalue < 0)
  {
    PCL_ERROR ("Could not load file !\n");
    return (-1);
  }

  return (0);
}

Test file

Error

$ ./ply_segfault 
Segmentation fault (core dumped)

It happens only with "special" PLY files. I don't know what causes this bug

@taketwo
Copy link
Member

taketwo commented May 16, 2014

I can confirm the bug. Segfault happens at the line

polygons_->back ().vertices.reserve (size);

in pcl::PLYReader::faceVertexIndicesBeginCallback(). Apparently, either the memory for polygons_ is not initialized at that moment, or the vector is empty.

@VictorLamoine
Copy link
Contributor Author

I'm fed up with this poor PLY support 😡

From what I've debugged so far the seg fault happens in this loop when reading the first face.
The code is very dense and hard to debug, if anyone has information I'll be grateful.

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff721698c in __gnu_cxx::__normal_iterator<pcl::Vertices*, std::vector<pcl::Vertices, std::allocator<pcl::Vertices> > >::__normal_iterator (this=0x7fffffffb9a0, __i=@0x8: <error reading variable>) at /usr/include/c++/4.8/bits/stl_iterator.h:726
726       __normal_iterator(const _Iterator& __i) : _M_current(__i) { }

Test file

ply
format ascii 1.0
element vertex 4
property float x
property float y
property float z
element face 2
property list uchar int vertex_indices
end_header
0 0 0
0 0 1
0 1 0
0 1 1
3 0 1 2 
3 2 1 3

@taketwo
Copy link
Member

taketwo commented Oct 16, 2015

Fixed via #1371

@taketwo taketwo closed this as completed Oct 16, 2015
@Datoclement
Copy link

Is this fixed? I find this segfault with macOSX High Sierra 10.13.6 with Python 3.6. I test it with the test file above and it gives a segfault.

@SergioRAgostinho
Copy link
Member

PCL is still not officially supporting Python bindings. This means you are using custom Python bindings made from another project. It might happen that this project is still wrapping an older version of the library and that is why you're still experiencing this bug.

@rivertam
Copy link

rivertam commented Oct 16, 2019

This seems to still be occurring for me.

My program:

#include <pcl/visualization/cloud_viewer.h>
#include <pcl/io/ply_io.h>

int main() {
  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>());
  std::cout << "loading" << std::endl;
  pcl::io::loadPLYFile("/home/rivertam/example.ply", *cloud);
  std::cout << "loaded" << std::endl;

  pcl::visualization::CloudViewer viewer("Simple Cloud Viewer");
  viewer.showCloud(cloud);
  while (!viewer.wasStopped()) { }

  return 0;
}

and my CMakeLists.txt:

cmake_minimum_required(VERSION 3.1.0)

project(claudia)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z -g -pthread -Wall")

find_package(PCL 1.7 REQUIRED COMPONENTS common io visualization)

include_directories(${PCL_INCLUDE_DIRS})

link_directories(${PCL_LIBRARY_DIRS})

add_definitions(${PCL_DEFINITIONS})

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} ${PCL_LIBRARIES} ${PCL_LIBRARY_DIRS})

The output is:

loading
[1]    31531 segmentation fault (core dumped)  ./claudia

I'm almost positive it's because of the PLY. I probably did something wrong (the ply may be even corrupt) but a segfault shouldn't happen anyways.

@kunaltyagi
Copy link
Member

kunaltyagi commented Oct 16, 2019

The fix was applied in PCL 1.8 and you're using PCL 1.7 (released in 2014) which means either you'll have to backport it yourself or upgrade to a newer version of PCL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Type of issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants