[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#91935: libc6: iconv breaks on illegal input sequence



gotom@debian.or.jp (GOTO Masanori)  wrote on 16.01.05 in <3n8uI-2Lj-7@gated-at.bofh.it>:

> The bug #91935[1] has been reported for a long time.  But I don't get
> any replys.  Could you check your problems described in #91935?  If
> you still have trouble with it, please let me know.  If there's no
> more report, I'll close this bug marked as fixed.
>
> [1] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=91935

Why on earth do you need *me* for that? Instructions for reproducing the  
bug are in the report, and don't depend on anything exotic. What's so hard  
about checking it yourself?!

Slightly modernized (because of iconv changes) command line and test  
program source - I suggest putting something like that in a test suite:

iconv --list | tr ' ,' '\n' | grep / | env - sort -u > iconv.out.s

#include <iconv.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void report(const char *what, int who, const char *when)
{
	fprintf(stderr, "ictest: %s: %s:%d: %s\n", what, __FILE__, who, when);
	perror("errno");
	abort();
}
#define CHECK(cond) do { if (!(cond)) report(#cond, __LINE__, ""); } while(0)
#define CHECKI(cond, info) do { if (!(cond)) report(#cond, __LINE__, info); } while(0)

FILE *charsets;

FILE *out;

wchar_t w;

char cs[8192];
char buf[819200];
char outbuf[819200];

iconv_t ic;

int main(int argc, char *argv[])
{
	CHECK((charsets = fopen("iconv.out.s", "r")) != NULL);
	while (fgets(cs, sizeof(cs)-2, charsets)) {
		char *p;
		char *bp, *op;
		int bl, ol;
		int c;

		p = cs;
		while (*p && *p != '\n') p++;
		*p = '\0';
		if (cs[0] == '#') {
			printf("Skipping %s\n", cs);
		}
		else {
			printf("Processing %s\n", cs);

			CHECKI((ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1, cs);
			sprintf(buf, "%s.tab1", cs);
			bp = buf;
			while (*bp) {
				if (*bp == '/')
					*bp = '_';
				bp++;
			}
			CHECKI((out = fopen(buf, "w")), cs);
			op = outbuf;
			ol = sizeof(outbuf);
			for (c=0; c<100000; c++) {
				w = c;
				bp = (void *)&w;
				bl = sizeof(w);
				CHECKI(iconv(ic, &bp, &bl, &op, &ol) >= 0, cs);
			}
			CHECKI(fwrite(outbuf, 1, op-outbuf, out) == op-outbuf, cs);
			CHECKI(fclose(out) == 0, cs);
			CHECKI(iconv_close(ic) == 0, cs);

			CHECKI((ic = iconv_open("WCHAR_T", cs)) != (iconv_t)-1, cs);
			sprintf(buf, "%s.tab2", cs);
			bp = buf;
			while (*bp) {
				if (*bp == '/')
					*bp = '_';
				bp++;
			}
			CHECKI((out = fopen(buf, "w")), cs);
			bp = outbuf;
			bl = op-bp;
			op = buf;
			ol = sizeof(buf);
			CHECKI(iconv(ic, &bp, &bl, &op, &ol) >= 0, cs);
			CHECKI(fwrite(buf, 1, op-buf, out) == op-buf, cs);
			CHECKI(fclose(out) == 0, cs);
			CHECKI(iconv_close(ic) == 0, cs);

			
			CHECKI((ic = iconv_open(cs, "ASCII")) != (iconv_t)-1, cs);
			sprintf(buf, "%s.tag", cs);
			bp = buf;
			while (*bp) {
				if (*bp == '/')
					*bp = '_';
				bp++;
			}
			CHECKI((out = fopen(buf, "w")), cs);
			sprintf(buf, "charset \"%s\";\n", cs);
			bp = buf;
			bl = strlen(buf);
			op = outbuf;
			ol = sizeof(outbuf);
			CHECKI(iconv(ic, &bp, &bl, &op, &ol) >= 0, cs);
			CHECKI(fwrite(outbuf, 1, op-outbuf, out) == op-outbuf, cs);
			CHECKI(fclose(out) == 0, cs);
			CHECKI(iconv_close(ic) == 0, cs);

		}
	}
	CHECK(ferror(charsets) == 0);
	CHECK(fclose(charsets) == 0);
	return 0;
}

Current results:

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: 10646-1:1993//

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: 10646-1:1993/UCS4/

Processing CP939//
Speicherzugriffsfehler (core dumped)

Processing CSIBM932//
Speicherzugriffsfehler (core dumped)

Processing CSIBM939//
Speicherzugriffsfehler (core dumped)

Processing CSIBM943//
Speicherzugriffsfehler (core dumped)

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: E13B/

Processing IBM-932//
Speicherzugriffsfehler (core dumped)

Processing IBM-939//
Speicherzugriffsfehler (core dumped)

Processing IBM-943//
Speicherzugriffsfehler (core dumped)

Processing IBM932//
Speicherzugriffsfehler (core dumped)

Processing IBM939//
Speicherzugriffsfehler (core dumped)

Processing IBM943//
Speicherzugriffsfehler (core dumped)

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: ISO_5427:1981//

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: ISO_5428:1980//

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: ISO_646.IRV:1991//

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: ISO_6937-2:1983//

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: ISO_6937:1992//

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: ISO_8859-10:1992//

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: ISO_8859-14:1998//

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: ISO_8859-15:1998//

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: ISO_8859-1:1987//

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: ISO_8859-2:1987//

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: ISO_8859-3:1988//

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: ISO_8859-4:1988//

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: ISO_8859-5:1988//

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: ISO_8859-6:1987//

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: ISO_8859-7:1987//

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: ISO_8859-8:1988//

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: ISO_8859-9:1989//

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: NC_NC00-10:81//

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: TCVN5712-1:1993//

ictest: (ic = iconv_open(cs, "WCHAR_T")) != (iconv_t)-1: iccheck.c:46: WCHAR_T//

*** If glibc improves in this way, I'll verify those same bugs in ten  
years. Nice work! NOT.

MfG Kai



Reply to: