-
Notifications
You must be signed in to change notification settings - Fork 555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
segfault (dead loop) with Encoding, use open :locale, print STDERR #8761
Comments
From aa29@mail.ruTo: perlbug@perl.org This is a bug report for perl from aa29@aa29xp, PerlIO: Warning with char that does not map to STDERR encoding leads binmode(STDERR, ":encoding(cp866)"); Then Perl tries to encode to cp866 while flushing STDERR buffer, it ext\Encode\Encode.xs, line 153: if (check & ENCODE_WARN_ON_ERR){ But "\302\253" already is in the STDERR buffer, and Perl_warner just Flags: Site configuration information for perl v5.8.4: Configured by aa29 at Mon May 17 17:59:46 2004. Summary of my perl5 (revision 5 version 8 subversion 4) configuration: Locally applied patches: @INC for perl v5.8.4: Environment for perl v5.8.4: PATH=C:\cygwin\bin;C:\Tcl\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\Syst aa29 |
From bulb@ucw.czCreated by bulb@ucw.czHello, I have recently seen perl crashing with segfault for certain combinations of #!/usr/bin/perl This script crashes on 3 different systems. One is SuSE 9.0 with perl 5.8.1, The script does NOT crash when STDERR is replaced by STDOUT, but rather "\x{8336}" does not map to iso-8859-2 at perlio-bug.pl line 9. as expected. Since the contents of the perlio layer stack might be important bulb@efreet:~$ perl -MData::Dumper -MPerlIO -e 'print Dumper(PerlIO::get_layers(STDERR, details => 1))' bulb@efreet:~$ perl -MData::Dumper -MPerlIO -e 'print Dumper(PerlIO::get_layers(STDOUT, details => 1))' bulb@efreet:~$ perl -MData::Dumper -MPerlIO -e 'binmode(STDERR, ":encoding(iso-8859-2)"); print Dumper(PerlIO::get_layers(STDERR, details => 1))' bulb@efreet:~$ perl -MData::Dumper -MPerlIO -e 'binmode(STDOUT, ":encoding(iso-8859-2)"); print Dumper(PerlIO::get_layers(STDOUT, details => 1))' This is a distribution perl, which is stripped, so the backtrace won't be (gdb) bt And this goes on for THOUSANDS of lines. It ends LOOOONG way down by: #66106 0x00002aaaab813a27 in XS_Encode__XS_encode () from /usr/lib/perl/5.8/auto/Encode/Encode.so Feel free to ask for more information. Regards, Jan Hudec <bulb@ucw.cz> Perl Info
|
From bulb@ucw.czHello Again, I've played with the bug a little more and I include several more scripts, First, let's get rid of the dependence on UTF-8 in the mail. This is the #!/usr/bin/perl Now the next script does NOT crash. It works normally: #!/usr/bin/perl As you can see, the only difference is the line: $SIG{__WARN__} = sub { }; So it shows, that the problem is caused by printing to STDERR from a warning #!/usr/bin/perl Now if the print is not to STDERR, it works. The following script does not #!/usr/bin/perl The most surprising is this script though. The next script replaces STDERR #!/usr/bin/perl Now this script does crash, but in a DIFFERENT WAY. Instead of immediately "\x{8336}" does not map to ascii at perlio-bug4.pl line 3. And exits with status 2. Note, that this was on a terminal, where STDOUT is -- |
From @smpeters
The code is essentially going into an infinite loop. The code discovers Here's the fatal end of the stack trace. #0 0x080fc619 in Perl_sv_vcatpvfn (sv=0x933e5d8, |
The RT System itself - Status changed from 'new' to 'open' |
From pixel@mandriva.comThis is a bug report for perl from pixel@mandriva.com, this segfaults if the locale charset is not utf8: use open ':locale'; Flags: Site configuration information for perl v5.8.8: Configured by Mandriva at Fri Sep 8 20:00:54 CEST 2006. Summary of my perl5 (revision 5 version 8 subversion 8) configuration: Locally applied patches: @INC for perl v5.8.8: Environment for perl v5.8.8: |
From @eserte"pixel@mandriva.com (via RT)" <perlbug-followup@perl.org> writes:
This seems to be an endless loop. This part is repeated over and over #852 0x282f9fc8 in PerlIOEncode_flush (f=0x81c0014) at encoding.xs:419 Regards,
-- |
The RT System itself - Status changed from 'new' to 'open' |
From @eserte"pixel@mandriva.com (via RT)" <perlbug-followup@perl.org> writes:
Attached is a patch which provides a workaround for the problem by |
From @eserteperlio-encoding.patch#
#
# To apply this patch:
# STEP 1: Chdir to the source directory.
# STEP 2: Run the 'applypatch' program with this patch file as input.
#
# If you do not have 'applypatch', it is part of the 'makepatch' package
# that you can fetch from the Comprehensive Perl Archive Network:
# http://www.perl.com/CPAN/authors/Johan_Vromans/makepatch-x.y.tar.gz
# In the above URL, 'x' should be 2 or higher.
#
# To apply this patch without the use of 'applypatch':
# STEP 1: Chdir to the source directory.
# STEP 2: Run the 'patch' program with this file as input.
#
#### End of Preamble ####
#### Patch data follows ####
diff -up 'bleedperl/ext/PerlIO/encoding/encoding.xs' 'bleedperl3/ext/PerlIO/encoding/encoding.xs'
Index: ./ext/PerlIO/encoding/encoding.xs
Prereq: 0.3
--- ./ext/PerlIO/encoding/encoding.xs Tue Jun 13 21:29:10 2006
+++ ./ext/PerlIO/encoding/encoding.xs Mon Feb 5 22:41:59 2007
@@ -48,6 +48,7 @@ typedef struct {
SV *enc; /* the encoding object */
SV *chk; /* CHECK in Encode methods */
int flags; /* Flags currently just needs lines */
+ int inEncodeCall; /* trap recursive encode calls */
} PerlIOEncode;
#define NEEDS_LINES 1
@@ -147,6 +148,7 @@ PerlIOEncode_pushed(pTHX_ PerlIO * f, co
}
e->chk = newSVsv(get_sv("PerlIO::encoding::fallback", 0));
+ e->inEncodeCall = 0;
FREETMPS;
LEAVE;
@@ -404,6 +406,7 @@ PerlIOEncode_flush(pTHX_ PerlIO * f)
STRLEN len;
SSize_t count = 0;
if ((PerlIOBase(f)->flags & PERLIO_F_WRBUF) && (e->base.ptr > e->base.buf)) {
+ if (e->inEncodeCall) return 0;
/* Write case - encode the buffer and write() to layer below */
PUSHSTACKi(PERLSI_MAGIC);
SPAGAIN;
@@ -416,9 +419,12 @@ PerlIOEncode_flush(pTHX_ PerlIO * f)
XPUSHs(e->bufsv);
XPUSHs(e->chk);
PUTBACK;
+ e->inEncodeCall = 1;
if (call_method("encode", G_SCALAR) != 1) {
+ e->inEncodeCall = 0;
Perl_die(aTHX_ "panic: encode did not return a value");
}
+ e->inEncodeCall = 0;
SPAGAIN;
str = POPs;
PUTBACK;
@@ -453,6 +459,7 @@ PerlIOEncode_flush(pTHX_ PerlIO * f)
}
/* See if there is anything left in the buffer */
if (e->base.ptr < e->base.end) {
+ if (e->inEncodeCall) return 0;
/* Bother - have unread data.
re-encode and unread() to layer below
*/
@@ -472,9 +479,12 @@ PerlIOEncode_flush(pTHX_ PerlIO * f)
XPUSHs(str);
XPUSHs(e->chk);
PUTBACK;
+ e->inEncodeCall = 1;
if (call_method("encode", G_SCALAR) != 1) {
- Perl_die(aTHX_ "panic: encode did not return a value");
+ e->inEncodeCall = 0;
+ Perl_die(aTHX_ "panic: encode did not return a value");
}
+ e->inEncodeCall = 0;
SPAGAIN;
str = POPs;
PUTBACK;
#### End of Patch data ####
#### ApplyPatch data follows ####
# Data version : 1.0
# Date generated : Mon Feb 5 22:58:23 2007
# Generated by : makepatch 2.03
# Recurse directories : Yes
# Excluded files : (\A|/).*\~\Z
# (\A|/).*\.a\Z
# (\A|/).*\.bak\Z
# (\A|/).*\.BAK\Z
# (\A|/).*\.elc\Z
# (\A|/).*\.exe\Z
# (\A|/).*\.gz\Z
# (\A|/).*\.ln\Z
# (\A|/).*\.o\Z
# (\A|/).*\.obj\Z
# (\A|/).*\.olb\Z
# (\A|/).*\.old\Z
# (\A|/).*\.orig\Z
# (\A|/).*\.rej\Z
# (\A|/).*\.so\Z
# (\A|/).*\.Z\Z
# (\A|/)\.del\-.*\Z
# (\A|/)\.make\.state\Z
# (\A|/)\.nse_depinfo\Z
# (\A|/)core\Z
# (\A|/)tags\Z
# (\A|/)TAGS\Z
# v 'patchlevel.h' 4732 1160388693 33056
# p 'ext/PerlIO/encoding/encoding.xs' 16562 1170711719 0100440
#### End of ApplyPatch data ####
#### End of Patch kit [created: Mon Feb 5 22:58:23 2007] ####
#### Patch checksum: 99 3441 30793 ####
#### Checksum: 117 4065 16793 ####
|
From @eserte-- tkrevdiff - graphical display of diffs between revisions (RCS, CVS or SVN) |
From @rgarciaOn 05 Feb 2007 23:04:07 +0100, Slaven Rezic <slaven@rezic.de> wrote:
The patch might be interesting to prevent similar segfaults in the |
From @eserte"Rafael Garcia-Suarez" <rgarciasuarez@gmail.com> writes:
Yes, this is the problem, and this is what the patch tries to fix. The With the inEncodeCall flag I tried to prevent calling encode() again I am not sure if the patch is right, because Regards, -- tksm - Perl/Tk program for searching and replacing in multiple files |
From @rgarciaOn 06 Feb 2007 21:59:53 +0100, Slaven Rezic <slaven@rezic.de> wrote:
Thanks, applied as change #30213, adding also Pixel's test case. (and
I don't see why it wouldn't be.
I don't think so, since that wasn't designed for that apparently. |
@rgs - Status changed from 'open' to 'resolved' |
From @dcollinsnThis was fixed somewhere between 5.8.8 and 5.8.9 by this monster of a commit: f266b49 is the first bad commit Integrate: [ 28766] [ 28798] [ 28799] [ 28903] [ 29173] [ 29702] [ 29751] [ 30213] [ 30214] [ 30233] p4raw-id: //depot/maint-5.8/perl@30340 :100644 100644 fb9a35503bbd64f925752279f2d4d92ae4aec465 4b59564147fb0caec127a3dcdccdca435cf74027 M MANIFEST Test to follow. -- |
From @dcollinsnThis (RT #37234) is, in fact, a duplicate of RT #41442. 41442 /has/ a test, and their test is better than my test. So, merging and closing. -- |
@dcollinsn - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#41442 (status was 'resolved')
Searchable as RT41442$
The text was updated successfully, but these errors were encountered: