[Koha-bugs] [Bug 10400] Text::CSV_XS error-checking should be standardized

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Sat Jul 8 17:59:19 CEST 2023


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=10400

--- Comment #3 from Katrin Fischer <katrin.fischer at bsz-bw.de> ---
(In reply to Galen Charlton from comment #0)
> As reported by Doug Kingston on koha-devel on 2013-06-02, if version 0.97 of
> Text::CSV_XS is installed, it can segfault.  From Doug's email:
> 
> "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;
> }"
> 
> A ticket was opened with the maintainer of Text::CSV_XS
> (https://rt.cpan.org/Ticket/Display.html?id=85810), and he fixed the
> segfault bug in version 0.98 of the module.

koha-testing-docker shows the version installed as:

Text::CSV_XS (0.32 )    1.45 

So I guess we could assume that most installations have this fix by now.

> 
> Nonetheless, Koha code that uses Text::CSV_XS should follow the module's
> documentation more closely; in particular, it looks like the correct thing
> to do is the check the value of the $status returned by $csv->parse() before
> deciding whether to invoke error_input().

It looks like we do the status check on patron import:

        my $status  = $self->text_csv->parse($borrowerline);
        my @columns = $self->text_csv->fields();
        if ( !$status ) {
            push @missing_criticals, { badparse => 1, line => $line_number,
lineraw => decode_utf8($borrowerline) };
        }

But there has not been any change in Labels:

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;

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list