- entry_p += 3+length_data_entry+length_starting;
- base_address = entry_p+1;
- for (entry_p = 24; buf[entry_p] != ISO2709_FS; )
+ {
+ int l = 3 + length_data_entry + length_starting;
+ if (entry_p + l >= record_length)
+ {
+ yaz_log(YLOG_WARN, "MARC: Directory offset %d: end of record.",
+ entry_p);
+ return 0;
+ }
+ /* check for digits in length info */
+ while (--l >= 3)
+ if (!isdigit(*(const unsigned char *) (buf + entry_p+l)))
+ break;
+ if (l >= 3)
+ {
+ /* not all digits, so stop directory scan */
+ yaz_log(YLOG_LOG, "MARC: Bad directory");
+ break;
+ }
+ entry_p += 3 + length_data_entry + length_starting;
+ }
+ end_of_directory = entry_p;
+ if (base_address != entry_p+1)
+ {
+ yaz_log(YLOG_WARN, "MARC: Base address does not follow directory");
+ }
+ for (entry_p = 24; entry_p != end_of_directory; )