chrstphrchvz / perl-tcl-ptk

Tcl::pTk - Interface to Tcl/Tk with Perl/Tk compatible syntax
https://metacpan.org/pod/Tcl::pTk
Other
8 stars 2 forks source link

macOS segmentation fault by pasting "d’une" in Text widget #20

Closed TakamotoAI closed 2 years ago

TakamotoAI commented 3 years ago

Posted also here https://core.tcl-lang.org/tk/tktview?name=234ee4f83b since I thought it was a pure Tcl/Tk issue. More experimenting seems to point now to a tcl::pTk issue (but still unsure). I am using 6.9.11 compiled as Frameworks.

The application crashes with Segmentation fault: 11 on macOS (tested on Mojave and bigSur) when pasting text with special characters from any different application (example: La réalisation d’une ouverture). This does not happen if typed directly or copied and pasted from the same Tk application.

In Perl, it can reproduced with the following:

use Tcl::pTk;
$mw = MainWindow->new();
my $int = $mw->interp;

$mw->Scrolled('Text', -width => 40, -height => 10, -wrap => 'char', -bd => '1', -scrollbars => 'e')->pack(-expand => 1, -fill => 'both', -pady => 2, -padx => [2,0]);

$int->MainLoop;

I can not reproduce it a simple Text widget in Wish.

grid [text .myText -background red -foreground white -relief ridge -borderwidth 8 -padx 10
   -pady 10 -font {Helvetica -18 bold} -width 20 -height 5]

The incriminated character is this special apostrophe ’

TakamotoAI commented 3 years ago

I think the problem derives from this

$w->clipboardGet;

which is called in module Tcl::pTk::Clipboard. With 6.9.11, it seems that the characters ’ is passed in a way that makes it break. You can test it overriding the paste action as here.

my $t = $mw->Scrolled('Text', -width => 40, -height => 10, -wrap => 'char', -bd => '1', -scrollbars => 'e')->pack(-expand => 1, -fill => 'both', -pady => 2, -padx => [2,0]);
$t->Subwidget('scrolled')->bind('Text','<<Paste>>', \&paste);

sub paste{
  my $data = $t->clipboardGet;
}

PS: this issue does not happen with 6.9.10

TakamotoAI commented 3 years ago

To add something to the picture. It gives a segmentation error even with pure Tcl code inside a Eval

my $t = $mw->Scrolled('Text', -width => 40, -height => 10, -wrap => 'char', -bd => '1', -scrollbars => 'e')->pack(-expand => 1, -fill => 'both', -pady => 2, -padx => [2,0]);
$t->Subwidget('scrolled')->bind('Text','<<Paste>>', \&paste);

sub paste{
my $int = $mw->interp;          
$int->Eval(<<'EOS');                
set myVar [clipboard get]
EOS
}

Interesting enough, it does not crash with Entry widgets, which for me it makes even more obscure to understand. Looks like the Entry widget has a different way to get the Pasteboard?

chrstphrchvz commented 3 years ago

I have reproduced this using Tcl syntax; see upstream ticket. This is likely not something to address from Tcl::pTk, but very good that this issue was spotted and reported.

chrstphrchvz commented 2 years ago

This should be fixed in Tcl/Tk 8.6.12.