[Koha] Problems with Text::CSV_XS and t/Labels.t

Doug Kingston dpk at randomnotes.org
Mon Jun 3 09:08:02 NZST 2013


My last install was on 3.10.02 and all was well with the set of Perl
modules had then, which included Text::CSV_XS-0.85.  As I prepared to build
3.10.06, I upgraded my Perl modules as some additions were required in any
case.  After the cpan upgrades, 'make test' was failing for both my 3.10.02
and 3.10.06 build trees.  t/Labels.t would just exit after running the
first sub-test (use).

After a couple of days, I have tracked this down to a change
in Text/CSV_XS.pm:

*** Text-CSV_XS-0.85/blib/lib/Text/CSV_XS.pm    2011-09-07
12:34:16.000000000 +0100
--- .cpan/build/Text-CSV_XS-0.97-cJDgOc/blib/lib/Text/CSV_XS.pm 2013-03-30
14:58:47.000000000 +0000
***************
... (in the subroutine 'parse') ...

***************
*** 492,498 ****
      my $fflags = [];
      $self->{_STRING} = \$str;
      if (defined $str && $self->Parse ($str, $fields, $fflags)) {
-       $self->{_ERROR_INPUT} = undef;
        $self->{_FIELDS} = $fields;
        $self->{_FFLAGS} = $fflags;
        $self->{_STATUS} = 1;

I further tracked this down to the most recent change (0.96 -> 0.97 around
March 30th, 2013).  The changelog says:
diff Text-CSV_XS-0.96/ChangeLog
.cpan/build/Text-CSV_XS-0.97-cJDgOc/ChangeLog
0a1,5
> 0.97 - 2013-03-30, H.Merijn Brand
>     * Regain the speed from 0.91 (buffer back to 1k)
>     * Minor cleanup in XS code
>     * Add diag_verbose attribute
>

I guess this qualifies as a minor cleanup if you assume people won't call
error_input on no error condition.

The error from t/Labels.t is a segmentation fault when calling
$csv->error_input() in Labels/Label.pm.

sub _get_text_fields {
    my $format_string = shift;
    my $csv = Text::CSV_XS->new({allow_whitespace => 1});
    my $status = $csv->parse($format_string);
    my @sorted_fields = map {{ 'code' => $_, desc => $_ }}
                        map { $_ eq 'callnumber' ? 'itemcallnumber' : $_ }
# see bug 5653
                        $csv->fields();
    my $error = $csv->error_input();
    warn sprintf('Text field sort failed with this error: %s', $error) if
$error;
    return \@sorted_fields;
}

I think there is an error here in _get_text_fields where it calls
$csv->error_input() when there was no error.  In the past, it would get an
undef, but the the more recent CSV_XS.pm module, the attribute is not
defined at all and it seg faults.  I think error_input() should only be
called if $status != 1.

Comments?  I think this is a Koha bug.

Revertion to Text::CSV_XS-0.96 resolves the problem until we fix Koha.

Regards,
  -Doug-


More information about the Koha mailing list