This is the mail archive of the
libc-alpha@sourceware.cygnus.com
mailing list for the glibc project.
iconv program produces invalid output
- To: libc-alpha at sourceware dot cygnus dot com
- Subject: iconv program produces invalid output
- From: Bruno Haible <haible at ilog dot fr>
- Date: Fri, 10 Dec 1999 21:16:49 +0100 (MET)
Hi,
The iconv program, when used to convert to some stateful encoding, produces
incomplete output. This is because it fails to emit the shift sequence needed
to return to the initial state.
Example session:
$ # Use libiconv-0.2. glibc iconv does not support UTF-7 yet.
$ export LD_PRELOAD=/usr/local/lib/libiconv_plug.so
$ hex () {
hexdump -e '"%06.6_ax " 16/1 "%02X "' -e '" " 16/1 "%_p" "\n"' "$@"
}
$ printf "Au" | iconv -f UCS-2 -t UTF-7 | hex
000000 2B 51 58 +QX
This is incorrect, the correct output would be
000000 2B 51 58 55 2D +QXU-
And indeed it is incomplete UTF-7:
$ printf "Au" | iconv -f UCS-2 -t UTF-7 | iconv -f UTF-7 -t UTF-8
iconv: incomplete character or shift sequence at end of buffer
The fix is to call iconv(cd,NULL,....) at the end.
*** glibc-2.1.1/iconv/iconv_prog.c.bak Wed Jan 20 18:11:51 1999
--- glibc-2.1.1/iconv/iconv_prog.c Fri Dec 10 10:21:28 1999
***************
*** 330,337 ****
}
if (n != (size_t) -1)
! /* Everything is processed. */
! break;
if (errno != E2BIG)
{
--- 330,347 ----
}
if (n != (size_t) -1)
! {
! /* Everything is processed. */
! if (addr != NULL)
! {
! /* One more round, to return to the initial state. */
! addr = NULL;
! len = 1;
! continue;
! }
! else
! break;
! }
if (errno != E2BIG)
{