]> granicus.if.org Git - file/commitdiff
Fix thumbs parsing (wrong offsets, skip first entry, pack)
authorChristos Zoulas <christos@zoulas.com>
Sat, 28 Feb 2015 00:18:02 +0000 (00:18 +0000)
committerChristos Zoulas <christos@zoulas.com>
Sat, 28 Feb 2015 00:18:02 +0000 (00:18 +0000)
src/cdf.c

index 951f1f2c1aa65f563e779bd11a399adaa0cc5c1e..9489f39e14bad73bcd7e5b5214f49b19a6700267 100644 (file)
--- a/src/cdf.c
+++ b/src/cdf.c
@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: cdf.c,v 1.74 2015/01/11 17:00:23 christos Exp $")
+FILE_RCSID("@(#)$File: cdf.c,v 1.75 2015/02/27 21:16:55 christos Exp $")
 #endif
 
 #include <assert.h>
@@ -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 <filename>\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