develooper Front page | perl.perl5.porters | Postings from May 2013

[perl #117537] PerlIO, STDERR and "encoding" layer problem

Thread Previous | Thread Next
From:
Victor Efimov via RT
Date:
May 9, 2013 19:16
Subject:
[perl #117537] PerlIO, STDERR and "encoding" layer problem
Message ID:
rt-3.6.HEAD-6955-1368126997-233.117537-15-0@perl.org
Ah, no, seems it didn't help.

Here is another PoC
Hangs on Ubuntu 10.04 perl 5.10.1 and Ubuntu 12.04 server, perl 5.14.2

#!/usr/bin/perl
use Encode;
use PerlIO::encoding;
use strict;
use warnings;
use utf8;

$PerlIO::encoding::fallback = Encode::FB_QUIET;
binmode STDERR, ":encoding(koi8-r)";
my $i = 1;


for my $a1 (qw/а б в й ё/) {
for my $a2 (qw/А /) {
for my $a3 (qw/А Б В Г Д /) {
	print STDERR encode("UTF-8", "Автопарк".$a1.$a2.$a3);
	++$i;
	print "i=$i\n";
}
}
}
__END__





On Fri Apr 26 06:38:36 2013, vsespb wrote:
> Hello.
> 
> Seems it helps indeed.
> 
> One of examples which hangs (I was able to reproduce only on FreeBSD 9)
> 
> perl -MEncode -MCarp -e 'binmode STDERR, ":encoding(koi8-r)"; croak
> "\320\220\320\262\321\202\320\276\320\277\320\260\321\200\320\272"'
> 
> With fallback:
> 
> perl -MEncode -MCarp -MPerlIO::encoding -e 'use strict;
> $PerlIO::encoding::fallback = Encode::FB_QUIET; binmode STDERR,
> ":encoding(koi8-r)"; croak
> "\320\220\320\262\321\202\320\276\320\277\320\260\321\200\320\272"'
> 
> does not hang.
> 
> Thanks!
> 
> I still think it should be documented better.
> 
> BTW Possible example of hang in real world application (that's how
> actually this happened to me):
> 
> When "confess" is used, it prints a stacktrace with function parameters.
> And some parameters can contain "random" binary data (user's file
> content, non-unicode filenames etc). That's pretty hard to debug if
> happen on user's machine - you don't even have a stacktrace and can't
> reproduce it ;(
> 
> 
> On Tue Apr 23 07:02:18 2013, LeonT wrote:
> > On Mon, Apr 8, 2013 at 8:33 PM, Victor Efimov <perlbug-
> > followup@perl.org> wrote:
> > >
> > > There is a ticket for Encode module
> > > https://rt.cpan.org/Ticket/Display.html?id=84493
> > > Problem that (probably Encode code) sometimes hangs in deep
> > recursion,
> > > when encoding layer set for STDERR and there are errors in encoding
> > processing.
> > >
> > > DANKOGAI suggest that it's actually PerlIO documentation problem and
> > that should
> > > be documented that PerlIO can't be used with STDERR (only exception
> > > :utf8 layer).
> > 
> > Saying "PerlIO can't be used with STDERR" is outright silly, because
> > you can't use STDERR without it. It makes sense that you're restricted
> > in what you can do with it, but those restrictions aren't well
> > defined.
> > 
> > > Thus I submit this bug here.
> > >
> > > This perldoc http://perldoc.perl.org/PerlIO.html does not mention
> > STDERR.
> > >
> > > Also open pragma doc http://perldoc.perl.org/open.html advertises
> > use
> > > of encoding with STDERR with single bytes encodings
> > > "On the other hand, if only output is chosen to be in
> > :encoding(koi8r)
> > > , a :std will cause only the STDOUT and STDERR to be in koi8r "
> > >
> > > I find also problem in the fact that carp/die/croak cannot be used
> > now
> > > with single-byte encoding locales.
> > >
> > > (othere related topics
> > https://rt.cpan.org/Ticket/Display.html?id=84282
> > > http://www.perlmonks.org/?node_id=1026042 )
> > 
> > How about setting the fallback value (somewhat documented in
> > PerlIO::encoding and Encode) to FB_QUIET? I'd guess that would solve
> > your problem.
> > 
> > Leon
> > 
> 
> 




---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=117537

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About