#!/usr/bin/env perl use strict; use warnings; $SIG{__DIE__} = sub { if ($^S == 0) { for my $s (0..$#_) { dcs($_[$s]); }; } }; sub dcs { my ($p1, $p2) = @_; my $cs=''; for (my $i=1; $i<3; $i++) { my ($package, $filename, $line, $subroutine) = caller($i); last if ( ! defined($package) ); print STDERR $filename; } print STDERR $p1; } sub mysub { die; } binmode STDERR, ":encoding(koi8-r)"; mysub(); 1;
This code just hangs if path to perl program contain UTF-8 characters (like 'perl тест/poc.pl').

It can reproduce it on two linux boxes (perl 10 and perl 12). Both have UTF-8 locale, UTF-8 filenames.

I hangs with different single-byte encodings (i tried koi-8 and cp1251). It hangs only when STDERR used and only when die is inside mysub.

The reason why I am trying to debug such a weird code in these weird circumstances - I have another script with similar code and a user with similar problem, however I cannot reproduce his problem in full. So I came to this PoC - I think maybe it's related.

Also this user does not do fancy things like using non-ASCII characters in filenames or using encoding different from locale encoding. However he runs FreeBSD and his locale is koi8-r (and my program sets STDERR encoding to KOI-8 too)

UPD: Perl hangs with 100% CPU usage and strace hangs with:
open("/usr/lib/perl/5.10/auto/Encode/Byte/Byte.so", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\240\\\3\0\0\0\ +0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0644, st_size=375048, ...}) = 0 mmap(NULL, 2470176, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, + 0) = 0x7fcef2b27000 mprotect(0x7fcef2b62000, 2093056, PROT_NONE) = 0 mmap(0x7fcef2d61000, 139264, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIX +ED|MAP_DENYWRITE, 3, 0x3a000) = 0x7fcef2d61000 close(3) = 0 mprotect(0x7fcef2d61000, 135168, PROT_READ) = 0
UPD: Shortest PoC:
#!/usr/bin/env perl use strict; use warnings; use Carp; $SIG{__DIE__} = sub { print STDERR $_ for (@_); }; binmode STDERR, ":encoding(koi8-r)"; sub mysub { croak; } mysub(); 1;
Again, should be ran as 'perl тест/poc.pl'. In this version die() does not reproduce problem - only 'croak'. Also cp1251 works without problem.

In reply to Weird STDERR/SIGDIE/Encodings issue by vsespb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.