Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
segfault on stack overflow when reading marshaled data #5318
Original bug ID: 5318
The attached code implements a doubly linked list, following the implementation of queues from the standard library.
The program sigfaults when reading the marshaled data of a doubly linked list of length more than 100000 (the minimal length for which it crashes is between 90000 and 100000). It works fine for smaller values.
tested with ocaml, ocamlc, and ocamlopt on a 64 bit machine running Linux
Comment author: @lefessan
Unfortunately, your data structure is too deep for Marshal.from_string which triggers a stack overflow. Marshal.from_string is optimized for trees, i.e. depth in log(n), and simple lists. You should consider either changing the representation of your doubly linked list, or save it into an array first, save the array with Marshal.to_string, and then do the reverse when unmarshaling.
Fixing this would require implementing another marshal/unmarshal couple, more expensive in memory, but without recursion on the stack.
Comment author: pascal_cuoq
I am relatively sure that the implementation of unmarshal for OCaml 3.12 available in http://frama-c.com/download/frama-c-Nitrogen-20111001.tar.gz (files external/un*.ml*) and documented at http://blog.frama-c.com/public/unmarshal.pdf does not have this issue.