Subject: | Circular data structure in query causes segmentation fault |
Date: | Thu, 17 Jun 2010 18:34:02 -0400 |
To: | bug-MongoDB [...] rt.cpan.org |
From: | Arkadiy Kukarkin <arkadiy [...] mindhole.org> |
Perl segfaults when a structure with circular references is passed to
MongoCollection::query();
To reproduce:
#!/usr/bin/perl
use MongoDB;
my $mcon = MongoDB::Connection->new();
my $md = $mcon->get_database('test');
my $mc = $md->get_collection('test');
my $query = {};
$query->{'q'} = $query;
my $cur = $mc->query($query);
my @res = $cur->all();
This is v5.10.1 on x86_64-linux-gnu-thread-multi, MongoDB 0.33.
The short answer is, obviously, "don't do that", but a more graceful
way to handle this would be nice. I actually had (what I assume to be)
the same or a related bug come up in production code, which generated
the following backtrace:
*** glibc detected *** perl: malloc(): memory corruption: 0x0000000004923ce0 ***
*** glibc detected *** perl: malloc(): memory corruption: 0x0000000004923cc0 ***
** child 2696 finished (255)
======= Backtrace: =========
======= Backtrace: =========
/lib/libc.so.6(+0x775b6)[0x7fb41af265b6]
/lib/libc.so.6(+0x775b6)[0x7fb41af265b6]
/lib/libc.so.6(+0x7b6d8)[0x7fb41af2a6d8]
/lib/libc.so.6(+0x7b6d8)[0x7fb41af2a6d8]
/lib/libc.so.6(__libc_calloc+0xc4)[0x7fb41af2d424]
/lib/libc.so.6(__libc_calloc+0xc4)[0x7fb41af2d424]
/usr/lib/libperl.so.5.10(Perl_safesyscalloc+0x7b)[0x7fb41b96975b]
/usr/lib/libperl.so.5.10(Perl_safesyscalloc+0x7b)[0x7fb41b96975b]
/usr/lib/libperl.so.5.10(PerlIOBuf_get_base+0x2f)[0x7fb41b9f22af]
/usr/lib/libperl.so.5.10(PerlIOBuf_get_base+0x2f)[0x7fb41b9f22af]
/usr/lib/libperl.so.5.10(PerlIOBuf_write+0x1f2)[0x7fb41b9f38e2]
/usr/lib/libperl.so.5.10(PerlIOBuf_write+0x1f2)[0x7fb41b9f38e2]
/usr/lib/libperl.so.5.10(Perl_vcroak+0x3d)[0x7fb41b96a6ed]
/usr/lib/libperl.so.5.10(Perl_vcroak+0x3d)[0x7fb41b96a6ed]
/usr/local/lib/perl/5.10.1/auto/MongoDB/MongoDB.so(+0xaed9)[0x7fb4191b8ed9]
/usr/local/lib/perl/5.10.1/auto/MongoDB/MongoDB.so(perl_mongo_bson_to_sv+0x5d)[0x7fb4191b96ed]
/usr/local/lib/perl/5.10.1/auto/MongoDB/MongoDB.so(XS_MongoDB__Cursor_next+0x179)[0x7fb4191b4809]
/usr/lib/libperl.so.5.10(+0x97e05)[0x7fb41b96ce05]
/usr/local/lib/perl/5.10.1/auto/MongoDB/MongoDB.so(+0xaed9)[0x7fb4191b8ed9]
/usr/local/lib/perl/5.10.1/auto/MongoDB/MongoDB.so(perl_mongo_bson_to_sv+0x5d)[0x7fb4191b96ed]
/usr/local/lib/perl/5.10.1/auto/MongoDB/MongoDB.so(XS_MongoDB__Cursor_next+0x/usr/lib/libperl.so.5.10(Perl_pp_entersub+0x5a5)[0x7fb41b980045]
/usr/lib/libperl.so.5.10(Perl_pp_entersub+0x5a5)[0x7fb41b980045]
/usr/lib/libperl.so.5.10(perl_run+0x33c)[0x7fb41b9263cc]
perl(main+0xec)[0x400d7c]
/usr/lib/libperl.so.5.10(perl_run+0x33c)[0x7fb41b9263cc]
/lib/libc.so.6(__libc_start_main+0xfd)[0x7fb41aecdc4d]
perl[0x400bc9]
======= Memory map: ========
/lib/libc.so.6(__libc_start_main+0xfd)[0x7fb41aecdc4d]
perl[0x400bc9]
======= Memory map: ========
00400000-00401000 r-xp 00000000 08:03 18579737
/usr/bin/perl
00601000-00602000 r--p 00001000 08:03 18579737
/usr/bin/perl
00602000-00603000 rw-p 00002000 08:03 18579737
/usr/bin/perl
02508000-049c2000 rw-p 00000000 00:00 0 [heap]
7fb410000000-7fb410021000 rw-p 00000000 00:00 0
7fb410021000-7fb414000000 ---p 00000000 00:00 0
7fb4159a8000-7fb4159be000 r-xp 00000000 08:03 7413789
/lib/libgcc_s.so.1
7fb4159be000-7fb415bbd000 ---p 00016000 08:03 7413789
/lib/libgcc_s.so.1
7fb415bbd000-7fb415bbe000 r--p 00015000 08:03 7413789
/lib/libgcc_s.so.1
7fb415bbe000-7fb415bbf000 rw-p 00016000 08:03 7413789
/lib/libgcc_s.so.1
7fb415bbf000-7fb415bcc000 r-xp 00000000 08:03 18743629
/usr/local/lib/perl/5.10.1/auto/Params/Validate/Validate.so
7fb415bcc000-7fb415dcb000 ---p 0000d000 08:03 18743629
/usr/local/00400000-00401000 r-xp 00000000 08:03 18579737
/usr/bin/perl
00601000-00602000 r--p 00001000 08:03 18579737
/usr/bin/perl
00602000-00603000 rw-p 00002000 08:03 18579737
/usr/bin/perl
02508000-049c2000 rw-p 00000000 00:00 0 [heap]
7fb410000000-7fb410021000 rw-p 00000000 00:00 0
7fb410021000-7fb414000000 ---p 00000000 00:00 0
7fb4159a8000-7fb4159be000 r-xp 00000000 08:03 7413789
/lib/libgcc_s.so.1
7fb4159be000-7fb415bbd000 ---p 00016000 08:03 7413789
/lib/libgcc_s.so.1
7fb415bbd000-7fb415bbe000 r--p 00015000 08:03 7413789
/lib/libgcc_s.so.1
7fb415bbe000-7fb415bbf000 rw-p 00016000 08:03 7413789
/lib/libgcc_s.so.1
7fb415bbf000-7fb415bcc000 r-xp 00000000 08:03 18743629
/usr/local/lib/perl/5.10.1/auto/Params/Validate/Validate.so
7fb415bcc000-7fb415dcb000 ---p 0000d000 08:03 18743629
/usr/local/lib/perl/5.10.1/auto/Params/Validate/Validate.so
7fb415dcb000-7fb415dcc000 r--p 0000c000 08:03 18743629
/usr/local/lib/perl/5.10.1/auto/Params/Validate/Validate.so
7fb415dcc000-7fb415dcd000 rw-p 0000d000 08:03 18743629
/usr/local/lib/perl/5.10.1/auto/Params/Validate/Validate.so
7fb415dcd000-7fb415dd2000 r-xp 00000000 08:03 18737259
/usr/local/lib/perl/5.10.1/auto/DateTime/DateTime.so
7fb415dd2000-7fb415fd1000 ---p 00005000 08:03 18737259
/usr/local/lib/perl/5.10.1/auto/DateTime/DateTime.so
7fb415fd1000-7fb415fd2000 r--p 00004000 08:03 18737259
/usr/local/lib/perl/5.10.1/auto/DateTime/DateTime.so
7fb415fd2000-7fb415fd3000 rw-p 00005000 08:03 18737259
/usr/local/lib/perl/5.10.1/auto/DateTime/DateTime.so