[Bug locale/14008] iconv behavior is incorrect when character is not present in dest charset

michael at orlitzky dot com via Glibc-bugs <[email protected]> Wed, 08 Jul 2026 00:22:06 +0000
Newsgroups gmane.comp.lib.glibc.bugs
Message-ID <[email protected]/bugzilla/>
https://sourceware.org/bugzilla/show_bug.cgi?id=14008

Michael Orlitzky <michael at orlitzky dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |michael at orlitzky dot com

--- Comment #2 from Michael Orlitzky <michael at orlitzky dot com> ---
This is documented now, at least. From the glibc manual (manual/charset.texi):

> The conversion stops for one of three reasons... the third reason is that
> the input contains invalid characters or translation to the character
> encoding of the output is not possible.
> 
> ...
> 
> Since the character sets selected in the @code{iconv_open} call can be
> almost arbitrary, there can be situations where the input buffer contains
> valid characters, which have no identical representation in the output
> character set.  The behavior in this situation is undefined.  The
> @emph{current} behavior of @theglibc{} in this situation is to
> return with an error immediately.  This certainly is not the most
> desirable solution; therefore, future versions will provide better ones,
> but they are not yet finished.
> 
> If all input from the input buffer is successfully converted and stored
> in the output buffer, the function returns the number of non-reversible
> conversions performed.  In all other cases the return value is
> @code{(size_t) -1} and @code{errno} is set appropriately.

The kernel man-pages project also contains the following in iconv(3), which
looks to be borrowed from GNU libiconv's iconv(3):

> The conversion can stop for five reasons...
> 
> 2. A multibyte sequence is encountered that is valid but that cannot
> be translated to the character encoding of the output. This condition
> depends on the implementation and on the conversion descriptor. In the
> GNU C library and GNU libiconv, if cd was created without the suffix
> //TRANSLIT or //IGNORE or //NON_IDENTICAL_DISCARD, the conversion is
> strict: lossy conversions produce this condition... When this condition
> is met, the iconv function sets errno to EILSEQ and returns (size_t)(−1).
> *inbuf is left pointing to the beginning of the unconvertible multibyte
> sequence.

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