[Bug locale/32046] iconv -c fails to report input encoding errors if output buffer is full

fweimer at redhat dot com sourceware-bugzilla@sourceware.org
Fri Sep 20 11:57:00 GMT 2024


https://sourceware.org/bugzilla/show_bug.cgi?id=32046

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
   Target Milestone|---                         |2.41
         Resolution|---                         |FIXED

--- Comment #2 from Florian Weimer <fweimer at redhat dot com> ---
Fixed for 2.41 via:

commit 6cbf845fcdc76131d0e674cee454fe738b69c69d
Author: Florian Weimer <fweimer@redhat.com>
Date:   Fri Sep 20 13:10:54 2024 +0200

    iconv: Preserve iconv -c error exit on invalid inputs (bug 32046)

    In several converters, a __GCONV_ILLEGAL_INPUT result gets overwritten
    with __GCONV_FULL_OUTPUT.  As a result, iconv (the function) returns
    E2BIG instead of EILSEQ.  The iconv program does not see the original
    EILSEQ failure, does not recognize the invalid input, and may
    incorrectly exit successfully.

    To address this, a new __flags bit is used to indicate a sticky input
    error state.  All __GCONV_ILLEGAL_INPUT results are replaced with a
    function call that sets this new __GCONV_ENCOUNTERED_ILLEGAL_INPUT and
    returns __GCONV_ILLEGAL_INPUT.  The iconv program checks for
    __GCONV_ENCOUNTERED_ILLEGAL_INPUT and overrides the exit status.

    The converter changes introducing __gconv_mark_illegal_input are
    mostly mechanical, except for the res variable initialization in
    iconvdata/iso-2022-jp.c: this error gets overwritten with __GCONV_OK
    and other results in the following code.  If res ==
    __GCONV_ILLEGAL_INPUT afterwards, STANDARD_TO_LOOP_ERR_HANDLER below
    will handle it.

    The __gconv_mark_illegal_input changes do not alter the errno value
    set by the iconv function.  This is simpler to implement than
    reviewing each __GCONV_FULL_OUTPUT result and adjust it not to
    override a previous __GCONV_ILLEGAL_INPUT result.  Doing it that way
    would also change some E2BIG errors in to EILSEQ errors, so it had to
    be done conditionally (under a flag set by the iconv program only), to
    avoid confusing buffer management in other applications.

    Reviewed-by: DJ Delorie <dj@redhat.com>

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Glibc-bugs mailing list