Tux / Text-CSV_XS

perl5 module for composition and decomposition of comma-separated values
17 stars 20 forks source link

segmentation faults with serialised/deserialised objects from previous script runs #49

Closed shawnlaffan closed 1 year ago

shawnlaffan commented 1 year ago

Serialising and deserialising objects from previous script runs leads to segmentation faults.

See attached scripts for reproduction code using Storable and Sereal formats.

Tested using Strawberry Perl 5.38.0.1 on Windows and a perlbrew 5.36.0 on Ubuntu via WSL2. Text::CSV_XS version is latest (1.51).

Encoding and decoding within the same process works.

perl same_process.pl

However, encoding in one process and decoding in a later process results in a segmentation fault.

perl create_and_serialise.pl
perl decode.pl

gdb backtrace:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff777b5b9 in cx_c_xsParse ()
   from /home/user/perl5/perlbrew/perls/perl-5.36.0/lib/site_perl/5.36.0/x86_64-linux/auto/Text/CSV_XS/CSV_XS.so
(gdb) bt
#0  0x00007ffff777b5b9 in cx_c_xsParse ()
   from /home/user/perl5/perlbrew/perls/perl-5.36.0/lib/site_perl/5.36.0/x86_64-linux/auto/Text/CSV_XS/CSV_XS.so
#1  0x00007ffff777f7fb in cx_xsParse ()
   from /home/user/perl5/perlbrew/perls/perl-5.36.0/lib/site_perl/5.36.0/x86_64-linux/auto/Text/CSV_XS/CSV_XS.so
#2  0x00007ffff777fc6d in XS_Text__CSV_XS_Parse ()
   from /home/user/perl5/perlbrew/perls/perl-5.36.0/lib/site_perl/5.36.0/x86_64-linux/auto/Text/CSV_XS/CSV_XS.so
#3  0x000055555566ca4e in Perl_pp_entersub ()
#4  0x0000555555662ea3 in Perl_runops_standard ()
#5  0x00005555555cbf07 in perl_run ()
#6  0x00005555555a2292 in main ()

create_and_serialise.pl.txt decode.pl.txt same_process.pl.txt

Tux commented 1 year ago

On Linux 6.5.3-1-default [openSUSE Tumbleweed 20230915] using 5.38.0-x86_64-linux-thread-multi-quadmath I cannot reproduce. These are the installed versions of modules used:

$ perl -d:TraceUse issue-49-ed.pl
Done stroring
Parsed storable
Done storable
Parsed sereal
Done sereal
Modules used from issue-49-ed.pl:
   1.  warnings 1.65, issue-49-ed.pl line 4 [main]
   2.  Text::CSV_XS 1.51, issue-49-ed.pl line 6 [main]
   3.    strict 1.12, Text/CSV_XS.pm line 18
   4.    XSLoader 0.32, Text/CSV_XS.pm line 22
  10.      IO::Handle 1.52, XSLoader.pm line 112 [Devel::TraceUse]
  11.        Symbol 1.09, IO/Handle.pm line 266
  12.        SelectSaver 1.02, IO/Handle.pm line 267
  13.        IO 1.52, IO/Handle.pm line 268
   5.    Carp 1.54, Text/CSV_XS.pm line 23
   6.      overloading 0.02, Carp.pm line 170
   7.      Exporter 5.77, Carp.pm line 224
  20.        Exporter::Heavy 5.77, Exporter.pm line 13
   8.    vars 1.05, Text/CSV_XS.pm line 25
   9.      warnings::register 1.05, vars.pm line 7
  14.  Sereal::Encoder 5.004, issue-49-ed.pl line 7 [main]
  15.    constant 1.33, Sereal/Encoder.pm line 74
  16.  Sereal::Decoder 5.004, issue-49-ed.pl line 8 [main]
  17.  Storable 3.32, issue-49-ed.pl line 9 [main]
  18.    Log::Agent, Storable.pm line 49 (FAILED)
  19.    Fcntl 1.15, Storable.pm line 84
  21.  IO::File 1.52, issue-49-ed.pl line 19 (eval 7) [main]
  22.    IO::Seekable 1.52, IO/File.pm line 132

I will try to reproduce on other boxes

Tux commented 1 year ago

Hah!

$ perl5.36.0 issue-49-ed.pl
Done stroring
Parsed storable
Done storable
Parsed sereal
Done sereal
$ perl5.36.0 issue-49-e.pl
Done
$ perl5.36.0 issue-49-d.pl
Segmentation fault (core dumped)
$ perl5.36.0 -d:TraceUse issue-49-ed.pl
Done stroring
Parsed storable
Done storable
Parsed sereal
Done sereal
Modules used from issue-49-ed.pl:
   1.  warnings 1.58, issue-49-ed.pl line 4 [main]
   2.  Text::CSV_XS 1.51, issue-49-ed.pl line 6 [main]
   3.    strict 1.12, Text/CSV_XS.pm line 18
   4.    XSLoader 0.31, Text/CSV_XS.pm line 22
  10.      IO::Handle 1.51, XSLoader.pm line 112 [Devel::TraceUse]
  11.        Symbol 1.09, IO/Handle.pm line 266
  12.        SelectSaver 1.02, IO/Handle.pm line 267
  13.        IO 1.51, IO/Handle.pm line 268
   5.    Carp 1.52, Text/CSV_XS.pm line 23
   6.      overloading 0.02, Carp.pm line 170
   7.      Exporter 5.77, Carp.pm line 224
  20.        Exporter::Heavy 5.77, Exporter.pm line 13
   8.    vars 1.05, Text/CSV_XS.pm line 25
   9.      warnings::register 1.04, vars.pm line 7
  14.  Sereal::Encoder 5.004, issue-49-ed.pl line 7 [main]
  15.    constant 1.33, Sereal/Encoder.pm line 74
  16.  Sereal::Decoder 5.004, issue-49-ed.pl line 8 [main]
  17.  Storable 3.26, issue-49-ed.pl line 9 [main]
  18.    Log::Agent, Storable.pm line 49 (FAILED)
  19.    Fcntl 1.15, Storable.pm line 84
  21.  IO::File 1.51, issue-49-ed.pl line 19 (eval 7) [main]
  22.    IO::Seekable 1.51, IO/File.pm line 132

Storable-3.32 is not (yet) standalone available on CPAN, but upgrading it in 5.36.0 from blead does not fix the coredump IO-File-1.52 is not (yet) standalone available on CPAN, but upgrading it in 5.36.0 from blead does not fix the coredump

/me continues digging

Tux commented 1 year ago

Can you try https://github.com/Tux/Text-CSV_XS/commit/ed952b49af26ff9e29cb0d576b013fcf5eb59741 ?

shawnlaffan commented 1 year ago

Thanks. Unfortunately it still segfaults on my machine when testing with perlbrew 5.36 via Ubuntu on WSL2.

The gdb backtrace is the same as reported above, although neither perl nor Text::CSV_XS have been built with debugging symbols so it won't have the full details.

Tux commented 1 year ago

Grrrr, I meanwhile can also reproduce in Windows/WSL2/openSUSE

On it, but with no high prio. Lots of other stuff on my plate too

Tux commented 1 year ago

Ok, what about https://github.com/Tux/Text-CSV_XS/commit/87e53b9afcb0358355f1962e48c78864838d990b ?

shawnlaffan commented 1 year ago

That looks to do the trick. Works on both Strawberry Perl and WSL2/Ubuntu used for the initial report.

Thanks for the rapid responses.

Tux commented 1 year ago

Released 1.52