From: Adam Dickmeiss Date: Fri, 9 Mar 2007 08:39:38 +0000 (+0000) Subject: Fixed yaz_iconv to return YAZ_ICONV_EINVAL if an incomplete MARC-8 X-Git-Tag: YAZ.2.1.54~14 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=19c0b332044f06ee33eaf66ca92675d9cda8d1b9;p=yaz-moved-to-github.git Fixed yaz_iconv to return YAZ_ICONV_EINVAL if an incomplete MARC-8 combo sequence is met. Before the error was not set so it would be unknown. --- diff --git a/src/siconv.c b/src/siconv.c index 1cd81ed..8916561 100644 --- a/src/siconv.c +++ b/src/siconv.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: siconv.c,v 1.33 2007-01-18 14:45:05 adam Exp $ + * $Id: siconv.c,v 1.34 2007-03-09 08:39:38 adam Exp $ */ /** * \file siconv.c @@ -394,6 +394,13 @@ static unsigned long yaz_read_marc8 (yaz_iconv_t cd, unsigned char *inp, for (cd->comb_size = 0; cd->comb_size < 8; cd->comb_size++) { int comb = 0; + if (inbytesleft == 0 && cd->comb_size) + { + cd->my_errno = YAZ_ICONV_EINVAL; + x = 0; + *no_read = 0; + break; + } x = yaz_read_marc8_comb(cd, inp, inbytesleft, no_read, &comb); if (!comb || !x) break; diff --git a/test/tsticonv.c b/test/tsticonv.c index d1ce8cc..43455ad 100644 --- a/test/tsticonv.c +++ b/test/tsticonv.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: tsticonv.c,v 1.24 2007-01-03 08:42:16 adam Exp $ + * $Id: tsticonv.c,v 1.25 2007-03-09 08:39:38 adam Exp $ */ #if HAVE_CONFIG_H @@ -90,19 +90,20 @@ static int tst_convert(yaz_iconv_t cd, const char *buf, const char *cmpbuf) char outbuf[12]; size_t inbytesleft = strlen(buf); const char *inp = buf; - while (inbytesleft) + int rounds = 0; + for (rounds = 0; inbytesleft && rounds < sizeof(outbuf); rounds++) { size_t outbytesleft = sizeof(outbuf); char *outp = outbuf; size_t r = yaz_iconv(cd, (char**) &inp, &inbytesleft, &outp, &outbytesleft); + wrbuf_write(b, outbuf, outp - outbuf); if (r == (size_t) (-1)) { int e = yaz_iconv_error(cd); if (e != YAZ_ICONV_E2BIG) break; } - wrbuf_write(b, outbuf, outp - outbuf); } if (wrbuf_len(b) == strlen(cmpbuf) && !memcmp(cmpbuf, wrbuf_buf(b), wrbuf_len(b))) @@ -350,6 +351,11 @@ static void tst_marc8_to_utf8(void) /* COMBINING ACUTE ACCENT */ YAZ_CHECK(tst_convert(cd, "Cours de mathâe", "Cours de mathe\xcc\x81")); + + + YAZ_CHECK(tst_convert(cd, "a\xea\x1e", "a\x1e\xcc\x8a")); + + YAZ_CHECK(tst_convert(cd, "a\xea", "a")); yaz_iconv_close(cd); } diff --git a/util/yaziconv.c b/util/yaziconv.c index 35e38e3..bf3b922 100644 --- a/util/yaziconv.c +++ b/util/yaziconv.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: yaziconv.c,v 1.6 2007-01-03 08:42:16 adam Exp $ + * $Id: yaziconv.c,v 1.7 2007-03-09 08:39:38 adam Exp $ */ #if HAVE_CONFIG_H @@ -81,7 +81,7 @@ void convert (FILE *inf, yaz_iconv_t cd, int verbose) } if (r == 0) { - fprintf (stderr, "invalid sequence\n"); + fprintf (stderr, "invalid sequence due to missing input\n"); return ; } inbytesleft += r;