Re: Bug in Gtk3::FileFilter?



On 17.12.19 21:45, Kerenoc Kerenoc via gtk-perl-list wrote:
In the process of migrating the Perl application GCstar from Gtk2 to
Gtk3 (https://gitlab.com/Kerenoc/GCstar/tree/Gtk3), I stumbled upon a
possible bug of the add_custom method of FileFilter. When used in the
"Save" mode of a FileChooserDialog, editing a file name in the input
form induces a segmentation fault, a very impolite behaviour for an
interpreted language! It happens at least on Debian 10 (perl v5.28.1,
libgtk-3-0  3.24.5-1) and Fedora 31 (perl v5.30.1, gtk3 3.24.13-1.fc31)
but strangely enough not on Windows!

This does indeed seem to be a bug in Gtk3/Glib::Object::Introspection.
The problem is with this call to add_custom():

    $filter->add_custom('filename', sub {
        my $ctx = shift;
        return 0 if ((! defined $ctx) || (! defined $ctx->{filename}));
        my $filename = lc($ctx->{filename});
        return ($filename =~ m/.html?$/);
        });

On the C level, this sets up the filter info struct ($ctx in the above)
to only contain a valid filename.  The other fields contain garbage.
But the C -> Perl converter does not know this and tries to access these
other fields anyways, hence the occasional crash.

Workarounds:

* Use $filter->add_custom([qw/filename uri display-name mime-type/],
  sub { ... }) to ensure that all fields contain valid data.

* Simply use something like $filter->add_pattern('*.[hH][tT][mM][lL]?').


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]