X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmarcdisp.c;h=be233a7c4d365293080a5eb8bfaded7062ae5b4c;hb=af2e686d7372a0a2f4175cbe46d99fadd64bb465;hp=6c7ba4c8286a1b89d1057524493e097a33cc49e2;hpb=60a702f390f7e2addfdab79f2328db3ba2897c8b;p=yaz-moved-to-github.git diff --git a/src/marcdisp.c b/src/marcdisp.c index 6c7ba4c..be233a7 100644 --- a/src/marcdisp.c +++ b/src/marcdisp.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: marcdisp.c,v 1.16 2005-02-08 13:51:30 adam Exp $ + * $Id: marcdisp.c,v 1.18 2005-02-25 17:04:45 adam Exp $ */ /** @@ -99,18 +99,12 @@ int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf, int bsize, WRBUF wr) || mt->xml == YAZ_MARC_MARCXML || mt->xml == YAZ_MARC_XCHANGE) produce_warnings = 1; - wrbuf_rewind(wr); - record_length = atoi_n (buf, 5); if (record_length < 25) { if (mt->debug) - { - char str[40]; - wrbuf_printf(wr, "\n", record_length); - } return -1; } memcpy(lead, buf, 24); /* se can modify the header for output */ @@ -246,10 +240,10 @@ int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf, int bsize, WRBUF wr) if (entry_p >= record_length) return -1; } - if (mt->debug && base_address != entry_p+1) + if (base_address != entry_p+1) { if (produce_warnings) - wrbuf_printf (wr," \n", base_address, entry_p+1); } base_address = entry_p+1; @@ -277,8 +271,11 @@ int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf, int bsize, WRBUF wr) i = data_offset + base_address; end_offset = i+data_length-1; - while (buf[i] != ISO2709_RS && buf[i] != ISO2709_FS && - i < end_offset) + if (data_length <= 0 || data_offset < 0 || end_offset >= record_length) + return -1; + + while (i < end_offset && + buf[i] != ISO2709_RS && buf[i] != ISO2709_FS) i++; sz1 = 1+i - (data_offset + base_address); if (mt->iconv_cd) @@ -326,6 +323,15 @@ int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf, int bsize, WRBUF wr) entry_p += length_starting; i = data_offset + base_address; end_offset = i+data_length-1; + + if (data_length <= 0 || data_offset < 0 || end_offset >= record_length) + { + if (produce_warnings) + wrbuf_printf (wr," \n", + data_length, data_offset); + break; + } if (mt->debug) { @@ -428,7 +434,8 @@ int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf, int bsize, WRBUF wr) } if (identifier_flag) { - while (buf[i] != ISO2709_RS && buf[i] != ISO2709_FS && i < end_offset) + while (i < end_offset && + buf[i] != ISO2709_RS && buf[i] != ISO2709_FS) { int i0; i++; @@ -467,8 +474,9 @@ int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf, int bsize, WRBUF wr) break; } i0 = i; - while (buf[i] != ISO2709_RS && buf[i] != ISO2709_IDFS && - buf[i] != ISO2709_FS && i < end_offset) + while (i < end_offset && + buf[i] != ISO2709_RS && buf[i] != ISO2709_IDFS && + buf[i] != ISO2709_FS) i++; marc_cdata(mt, buf + i0, i - i0, wr); @@ -485,7 +493,8 @@ int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf, int bsize, WRBUF wr) else { int i0 = i; - while (buf[i] != ISO2709_RS && buf[i] != ISO2709_FS && i < end_offset) + while (i < end_offset && + buf[i] != ISO2709_RS && buf[i] != ISO2709_FS) i++; marc_cdata(mt, buf + i0, i - i0, wr); if (mt->xml == YAZ_MARC_ISO2709)