From: Christos Zoulas Date: Sat, 28 Feb 2015 00:18:02 +0000 (+0000) Subject: Fix thumbs parsing (wrong offsets, skip first entry, pack) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4bb34f069561f341d4131bd748d7a3e7678271b2;p=file Fix thumbs parsing (wrong offsets, skip first entry, pack) --- diff --git a/src/cdf.c b/src/cdf.c index 0097f38f..c979b1da 100644 --- a/src/cdf.c +++ b/src/cdf.c @@ -35,7 +35,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: cdf.c,v 1.75 2015/02/27 21:16:55 christos Exp $") +FILE_RCSID("@(#)$File: cdf.c,v 1.76 2015/02/28 00:18:02 christos Exp $") #endif #include @@ -1026,31 +1026,33 @@ cdf_unpack_catalog(const cdf_header_t *h, const cdf_stream_t *sst, CDF_SHORT_SEC_SIZE(h) : CDF_SEC_SIZE(h); const char *b = CAST(const char *, sst->sst_tab); const char *eb = b + ss * sst->sst_len; - size_t nr, i, k; + size_t nr, i, j, k; cdf_catalog_entry_t *ce; uint16_t reclen; const uint16_t *np; - for (nr = 0; b < eb; nr++) { + for (nr = 0;; nr++) { memcpy(&reclen, b, sizeof(reclen)); reclen = CDF_TOLE2(reclen); if (reclen == 0) break; b += reclen; + if (b > eb) + break; } + nr--; *cat = CAST(cdf_catalog_t *, malloc(sizeof(cdf_catalog_t) + nr * sizeof(*ce))); - (*cat)->cat_num = nr; ce = (*cat)->cat_e; memset(ce, 0, nr * sizeof(*ce)); b = CAST(const char *, sst->sst_tab); - for (i = 0; i < nr; i++, b += reclen) { - cdf_catalog_entry_t *cep = &ce[i]; + for (j = i = 0; i < nr; b += reclen) { + cdf_catalog_entry_t *cep = &ce[j]; uint16_t rlen; extract_catalog_field(uint16_t, ce_namlen, 0); - extract_catalog_field(uint16_t, ce_num, 2); - extract_catalog_field(uint64_t, ce_timestamp, 6); + extract_catalog_field(uint16_t, ce_num, 4); + extract_catalog_field(uint64_t, ce_timestamp, 8); reclen = cep->ce_namlen; if (reclen < 14) { @@ -1072,7 +1074,10 @@ cdf_unpack_catalog(const cdf_header_t *h, const cdf_stream_t *sst, for (k = 0; k < cep->ce_namlen; k++) cep->ce_name[k] = np[k]; /* XXX: CDF_TOLE2? */ cep->ce_name[cep->ce_namlen] = 0; + j = i; + i++; } + (*cat)->cat_num = j; return 0; } @@ -1431,7 +1436,10 @@ main(int argc, char *argv[]) cdf_dir_t dir; cdf_info_t info; const cdf_directory_t *root; - +#ifdef __linux__ +#define getprogname() __progname + extern char *__progname; +#endif if (argc < 2) { (void)fprintf(stderr, "Usage: %s \n", getprogname()); return -1; @@ -1484,7 +1492,7 @@ main(int argc, char *argv[]) cdf_dump_summary_info(&h, &scn); #endif if (cdf_read_user_stream(&info, &h, &sat, &ssat, &sst, - &dir, "Catalog", &scn) <= 0) + &dir, "Catalog", &scn) == -1) warn("Cannot read catalog"); #ifdef CDF_DEBUG else