It indeed appears to be a bug in PerlIO::encoding. See http://cpansearch.perl.org/src/RJBS/perl-5.18.1/ext/PerlIO-encoding/encoding.xs to note that "encode" and "decode" methods are simply called with a buffer full of bytes with no attempts to handle incomplete multi-byte characters across buffer boundaries.

To fix this efficiently, you'd want Encode's encode() and decode() methods (or similar) to support "tell me how many bytes on the end to save for later as they could be incomplete multi-byte characters in the desired encoding". Ah, I see FB_QUIET is already there for just that purpose. Unfortunately, using that completely defeats the purpose of allowing options like FB_WARN and FB_CROAK. Plus I don't see how that code makes it reasonable to detect invalid characters instead of just ending up in an endless loop of converting 0 bytes over and over.

It would be helpful for something similar to FB_QUIET to be defined as a bit that can be combined with FB_WARN or FB_CROAK such that failing at the first byte or (better) too far before the end of the buffer triggers the warn/croak but failing with a single, incomplete fragment of a multi-byte character on the end of the buffer acts like FB_QUIET would.

But surely that's already plenty of information for you to file the bug report, eh?

- tye        


In reply to Re^3: Unicode perlio error (when multibyte UTF-8 characters are split across block boundaries-- is it a perl bug or an I'm stupid bug? (source) by tye
in thread Unicode perlio error (when multibyte UTF-8 characters are split across block boundaries-- is it a perl bug or an I'm stupid bug? by DrWhy

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.