Hi all.

I'm working with a fleet of devices running Perl on a ARM chipset (armhf) that are experiencing an infrequent, random crash in SQL::Abstract (via DBIx::Class). I've not yet been able to reproduce it manually, our only clue to go off of has been the following log statement.

panic: stack_grow() negative count (-16777216) at /usr/share/perl5/SQL/Abstract.pm line 1493

I've found similar threads of https://rt-cpan.github.io/Public/Bug/Display/108578/ and https://github.com/Perl/perl5/issues/15013. But neither of which were fruitful.

My first observation was that -16777216 is 0xFF000000 as a 32-bit signed value. This makes me think it's due to a unsigned to signed cast gone wrong. However, adding 16 MiB to the stack seems incorrect as well. To me this screams memory corruption or an uninitialized value.

I ran it with the -d flag to get the following stack trace:

@ = SQL::Abstract::_join_sql_clauses(ref(DBIx::Class::SQLMaker), 'and' +, ref(ARRAY), ref(ARRAY)) called from file '/usr/share/perl5/SQL/Abst +ract.pm' line 678 @ = SQL::Abstract::_where_HASHREF(ref(DBIx::Class::SQLMaker), ref(HASH +), undef) called from file '/usr/share/perl5/SQL/Abstract.pm' line 54 +5 @ = SQL::Abstract::_recurse_where(ref(DBIx::Class::SQLMaker), ref(HASH +)) called from file '/usr/share/perl5/SQL/Abstract.pm' line 525 @ = SQL::Abstract::where(ref(DBIx::Class::SQLMaker), ref(HASH), ref(HA +SH)) called from file '/usr/share/perl5/SQL/Abstract.pm' line 469 @ = SQL::Abstract::select(ref(DBIx::Class::SQLMaker), ref(ARRAY), 'me. +id, me.name, me.value, me.modified_at', ref(HASH), ref(HASH)) called +from file '/usr/share/perl5/DBIx/Class/SQLMaker.pm' line 172 @ = DBIx::Class::SQLMaker::select(ref(DBIx::Class::SQLMaker), ref(ARRA +Y), ref(ARRAY), ref(HASH), ref(HASH)) called from file '/usr/share/pe +rl5/DBIx/Class/Storage/DBI.pm' line 1679 @ = DBIx::Class::Storage::DBI::_gen_sql_bind(ref(DBIx::Class::Storage: +:DBI::Pg), 'select', ref(ARRAY), ref(ARRAY)) called from file '/usr/s +hare/perl5/DBIx/Class/Storage/DBI.pm' line 1666 @ = DBIx::Class::Storage::DBI::_prep_for_execute(ref(DBIx::Class::Stor +age::DBI::Pg), 'select', ref(ARRAY), ref(ARRAY)) called from file '/u +sr/share/perl5/DBIx/Class/Storage/DBI.pm' line 1810 @ = DBIx::Class::Storage::DBI::_execute(ref(DBIx::Class::Storage::DBI: +:Pg), 'select', ref(ARRAY), ref(ARRAY), ref(HASH), ref(HASH)) called +from file '/usr/share/perl5/DBIx/Class/Storage/DBI.pm' line 2409 @ = DBIx::Class::Storage::DBI::_select(ref(DBIx::Class::Storage::DBI:: +Pg), ref(ARRAY), ref(ARRAY), ref(HASH), ref(HASH)) called from file ' +/usr/share/perl5/DBIx/Class/Storage/DBI.pm' line 2586 @ = DBIx::Class::Storage::DBI::select_single(ref(DBIx::Class::Storage: +:DBI::Pg), ref(ARRAY), ref(ARRAY), ref(HASH), ref(HASH)) called from +file '/usr/share/perl5/DBIx/Class/ResultSet.pm' line 1104

This puts us at the following function and line of the crash: https://github.com/dbsrgits/sql-abstract/blob/2972827e573b0217735b901088e69c994ba8d226/lib/SQL/Abstract.pm#L1493

sub _join_sql_clauses { my ($self, $logic, $clauses_aref, $bind_aref) = @_; if (@$clauses_aref > 1) { my $join = " " . $self->_sqlcase($logic) . " "; my $sql = '( ' . join($join, @$clauses_aref) . ' )'; return ($sql, @$bind_aref); } elsif (@$clauses_aref) { ##### CRASH TRIGGERED ON LINE 1493 BELOW ##### return ($clauses_aref->[0], @$bind_aref); # no parentheses } else { return (); # if no SQL, ignore @$bind_aref } }

However, trying to add a breakpoint to stack_grow() fails. From further research this is an internal symbol, so does not have a subroutine to match.

My questions are:

Versions: Perl version: 5.32.1 DBIx::Class version: 0.082841 SQL::Abstract version: 1.87

I appreciate any and all feedback, thank you all in advance. - Casey


In reply to Crash in stack_grow() with SQL::Abstract by Casey2255

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.