iconv program produces invalid output
Bruno Haible
haible@ilog.fr
Fri Dec 10 12:17:00 GMT 1999
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)
{
More information about the Libc-alpha
mailing list