2 * Copyright (c) 2008 Christos Zoulas
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
15 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
16 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
27 * Parse Composite Document Files, the format used in Microsoft Office
28 * document files before they switched to zipped XML.
29 * Info from: http://sc.openoffice.org/compdocfileformat.pdf
31 * N.B. This is the "Composite Document File" format, and not the
32 * "Compound Document Format", nor the "Channel Definition Format".
38 FILE_RCSID("@(#)$File: cdf.c,v 1.110 2017/12/19 00:21:21 christos Exp $")
61 #define DPRINTF(a) printf a, fflush(stdout)
71 #define NEED_SWAP (cdf_bo.u == (uint32_t)0x01020304)
73 #define CDF_TOLE8(x) ((uint64_t)(NEED_SWAP ? _cdf_tole8(x) : (uint64_t)(x)))
74 #define CDF_TOLE4(x) ((uint32_t)(NEED_SWAP ? _cdf_tole4(x) : (uint32_t)(x)))
75 #define CDF_TOLE2(x) ((uint16_t)(NEED_SWAP ? _cdf_tole2(x) : (uint16_t)(x)))
76 #define CDF_TOLE(x) (/*CONSTCOND*/sizeof(x) == 2 ? \
77 CDF_TOLE2(CAST(uint16_t, x)) : \
78 (/*CONSTCOND*/sizeof(x) == 4 ? \
79 CDF_TOLE4(CAST(uint32_t, x)) : \
80 CDF_TOLE8(CAST(uint64_t, x))))
81 #define CDF_GETUINT32(x, y) cdf_getuint32(x, y)
83 #define CDF_MALLOC(n) cdf_malloc(__FILE__, __LINE__, (n))
84 #define CDF_REALLOC(p, n) cdf_realloc(__FILE__, __LINE__, (p), (n))
85 #define CDF_CALLOC(n, u) cdf_calloc(__FILE__, __LINE__, (n), (u))
90 cdf_malloc(const char *file __attribute__((__unused__)),
91 size_t line __attribute__((__unused__)), size_t n)
93 DPRINTF(("%s,%zu: %s %zu\n", file, line, __func__, n));
99 cdf_realloc(const char *file __attribute__((__unused__)),
100 size_t line __attribute__((__unused__)), void *p, size_t n)
102 DPRINTF(("%s,%zu: %s %zu\n", file, line, __func__, n));
103 return realloc(p, n);
108 cdf_calloc(const char *file __attribute__((__unused__)),
109 size_t line __attribute__((__unused__)), size_t n, size_t u)
111 DPRINTF(("%s,%zu: %s %zu %zu\n", file, line, __func__, n, u));
119 _cdf_tole2(uint16_t sv)
122 uint8_t *s = (uint8_t *)(void *)&sv;
123 uint8_t *d = (uint8_t *)(void *)&rv;
133 _cdf_tole4(uint32_t sv)
136 uint8_t *s = (uint8_t *)(void *)&sv;
137 uint8_t *d = (uint8_t *)(void *)&rv;
149 _cdf_tole8(uint64_t sv)
152 uint8_t *s = (uint8_t *)(void *)&sv;
153 uint8_t *d = (uint8_t *)(void *)&rv;
166 * grab a uint32_t from a possibly unaligned address, and return it in
167 * the native host order.
170 cdf_getuint32(const uint8_t *p, size_t offs)
173 (void)memcpy(&rv, p + offs * sizeof(uint32_t), sizeof(rv));
174 return CDF_TOLE4(rv);
177 #define CDF_UNPACK(a) \
178 (void)memcpy(&(a), &buf[len], sizeof(a)), len += sizeof(a)
179 #define CDF_UNPACKA(a) \
180 (void)memcpy((a), &buf[len], sizeof(a)), len += sizeof(a)
183 cdf_tole2(uint16_t sv)
185 return CDF_TOLE2(sv);
189 cdf_tole4(uint32_t sv)
191 return CDF_TOLE4(sv);
195 cdf_tole8(uint64_t sv)
197 return CDF_TOLE8(sv);
201 cdf_swap_header(cdf_header_t *h)
205 h->h_magic = CDF_TOLE8(h->h_magic);
206 h->h_uuid[0] = CDF_TOLE8(h->h_uuid[0]);
207 h->h_uuid[1] = CDF_TOLE8(h->h_uuid[1]);
208 h->h_revision = CDF_TOLE2(h->h_revision);
209 h->h_version = CDF_TOLE2(h->h_version);
210 h->h_byte_order = CDF_TOLE2(h->h_byte_order);
211 h->h_sec_size_p2 = CDF_TOLE2(h->h_sec_size_p2);
212 h->h_short_sec_size_p2 = CDF_TOLE2(h->h_short_sec_size_p2);
213 h->h_num_sectors_in_sat = CDF_TOLE4(h->h_num_sectors_in_sat);
214 h->h_secid_first_directory = CDF_TOLE4(h->h_secid_first_directory);
215 h->h_min_size_standard_stream =
216 CDF_TOLE4(h->h_min_size_standard_stream);
217 h->h_secid_first_sector_in_short_sat =
218 CDF_TOLE4((uint32_t)h->h_secid_first_sector_in_short_sat);
219 h->h_num_sectors_in_short_sat =
220 CDF_TOLE4(h->h_num_sectors_in_short_sat);
221 h->h_secid_first_sector_in_master_sat =
222 CDF_TOLE4((uint32_t)h->h_secid_first_sector_in_master_sat);
223 h->h_num_sectors_in_master_sat =
224 CDF_TOLE4(h->h_num_sectors_in_master_sat);
225 for (i = 0; i < __arraycount(h->h_master_sat); i++)
226 h->h_master_sat[i] = CDF_TOLE4((uint32_t)h->h_master_sat[i]);
230 cdf_unpack_header(cdf_header_t *h, char *buf)
235 CDF_UNPACK(h->h_magic);
236 CDF_UNPACKA(h->h_uuid);
237 CDF_UNPACK(h->h_revision);
238 CDF_UNPACK(h->h_version);
239 CDF_UNPACK(h->h_byte_order);
240 CDF_UNPACK(h->h_sec_size_p2);
241 CDF_UNPACK(h->h_short_sec_size_p2);
242 CDF_UNPACKA(h->h_unused0);
243 CDF_UNPACK(h->h_num_sectors_in_sat);
244 CDF_UNPACK(h->h_secid_first_directory);
245 CDF_UNPACKA(h->h_unused1);
246 CDF_UNPACK(h->h_min_size_standard_stream);
247 CDF_UNPACK(h->h_secid_first_sector_in_short_sat);
248 CDF_UNPACK(h->h_num_sectors_in_short_sat);
249 CDF_UNPACK(h->h_secid_first_sector_in_master_sat);
250 CDF_UNPACK(h->h_num_sectors_in_master_sat);
251 for (i = 0; i < __arraycount(h->h_master_sat); i++)
252 CDF_UNPACK(h->h_master_sat[i]);
256 cdf_swap_dir(cdf_directory_t *d)
258 d->d_namelen = CDF_TOLE2(d->d_namelen);
259 d->d_left_child = CDF_TOLE4((uint32_t)d->d_left_child);
260 d->d_right_child = CDF_TOLE4((uint32_t)d->d_right_child);
261 d->d_storage = CDF_TOLE4((uint32_t)d->d_storage);
262 d->d_storage_uuid[0] = CDF_TOLE8(d->d_storage_uuid[0]);
263 d->d_storage_uuid[1] = CDF_TOLE8(d->d_storage_uuid[1]);
264 d->d_flags = CDF_TOLE4(d->d_flags);
265 d->d_created = CDF_TOLE8((uint64_t)d->d_created);
266 d->d_modified = CDF_TOLE8((uint64_t)d->d_modified);
267 d->d_stream_first_sector = CDF_TOLE4((uint32_t)d->d_stream_first_sector);
268 d->d_size = CDF_TOLE4(d->d_size);
272 cdf_swap_class(cdf_classid_t *d)
274 d->cl_dword = CDF_TOLE4(d->cl_dword);
275 d->cl_word[0] = CDF_TOLE2(d->cl_word[0]);
276 d->cl_word[1] = CDF_TOLE2(d->cl_word[1]);
280 cdf_unpack_dir(cdf_directory_t *d, char *buf)
284 CDF_UNPACKA(d->d_name);
285 CDF_UNPACK(d->d_namelen);
286 CDF_UNPACK(d->d_type);
287 CDF_UNPACK(d->d_color);
288 CDF_UNPACK(d->d_left_child);
289 CDF_UNPACK(d->d_right_child);
290 CDF_UNPACK(d->d_storage);
291 CDF_UNPACKA(d->d_storage_uuid);
292 CDF_UNPACK(d->d_flags);
293 CDF_UNPACK(d->d_created);
294 CDF_UNPACK(d->d_modified);
295 CDF_UNPACK(d->d_stream_first_sector);
296 CDF_UNPACK(d->d_size);
297 CDF_UNPACK(d->d_unused0);
301 cdf_zero_stream(cdf_stream_t *scn)
312 cdf_check_stream(const cdf_stream_t *sst, const cdf_header_t *h)
314 size_t ss = sst->sst_dirlen < h->h_min_size_standard_stream ?
315 CDF_SHORT_SEC_SIZE(h) : CDF_SEC_SIZE(h);
316 assert(ss == sst->sst_ss);
321 cdf_check_stream_offset(const cdf_stream_t *sst, const cdf_header_t *h,
322 const void *p, size_t tail, int line)
324 const char *b = (const char *)sst->sst_tab;
325 const char *e = ((const char *)p) + tail;
326 size_t ss = cdf_check_stream(sst, h);
327 /*LINTED*/(void)&line;
328 if (e >= b && (size_t)(e - b) <= ss * sst->sst_len)
330 DPRINTF(("%d: offset begin %p < end %p || %" SIZE_T_FORMAT "u"
331 " > %" SIZE_T_FORMAT "u [%" SIZE_T_FORMAT "u %"
332 SIZE_T_FORMAT "u]\n", line, b, e, (size_t)(e - b),
333 ss * sst->sst_len, ss, sst->sst_len));
339 cdf_read(const cdf_info_t *info, off_t off, void *buf, size_t len)
341 size_t siz = (size_t)off + len;
343 if ((off_t)(off + len) != (off_t)siz)
346 if (info->i_buf != NULL && info->i_len >= siz) {
347 (void)memcpy(buf, &info->i_buf[off], len);
351 if (info->i_fd == -1)
354 if (pread(info->i_fd, buf, len, off) != (ssize_t)len)
364 cdf_read_header(const cdf_info_t *info, cdf_header_t *h)
368 (void)memcpy(cdf_bo.s, "\01\02\03\04", 4);
369 if (cdf_read(info, (off_t)0, buf, sizeof(buf)) == -1)
371 cdf_unpack_header(h, buf);
373 if (h->h_magic != CDF_MAGIC) {
374 DPRINTF(("Bad magic %#" INT64_T_FORMAT "x != %#"
375 INT64_T_FORMAT "x\n",
376 (unsigned long long)h->h_magic,
377 (unsigned long long)CDF_MAGIC));
380 if (h->h_sec_size_p2 > 20) {
381 DPRINTF(("Bad sector size %hu\n", h->h_sec_size_p2));
384 if (h->h_short_sec_size_p2 > 20) {
385 DPRINTF(("Bad short sector size %hu\n",
386 h->h_short_sec_size_p2));
397 cdf_read_sector(const cdf_info_t *info, void *buf, size_t offs, size_t len,
398 const cdf_header_t *h, cdf_secid_t id)
400 size_t ss = CDF_SEC_SIZE(h);
401 size_t pos = CDF_SEC_POS(h, id);
403 return cdf_read(info, (off_t)pos, ((char *)buf) + offs, len);
407 cdf_read_short_sector(const cdf_stream_t *sst, void *buf, size_t offs,
408 size_t len, const cdf_header_t *h, cdf_secid_t id)
410 size_t ss = CDF_SHORT_SEC_SIZE(h);
411 size_t pos = CDF_SHORT_SEC_POS(h, id);
413 if (pos + len > CDF_SEC_SIZE(h) * sst->sst_len) {
414 DPRINTF(("Out of bounds read %" SIZE_T_FORMAT "u > %"
416 pos + len, CDF_SEC_SIZE(h) * sst->sst_len));
419 (void)memcpy(((char *)buf) + offs,
420 ((const char *)sst->sst_tab) + pos, len);
428 * Read the sector allocation table.
431 cdf_read_sat(const cdf_info_t *info, cdf_header_t *h, cdf_sat_t *sat)
434 size_t ss = CDF_SEC_SIZE(h);
435 cdf_secid_t *msa, mid, sec;
436 size_t nsatpersec = (ss / sizeof(mid)) - 1;
438 for (i = 0; i < __arraycount(h->h_master_sat); i++)
439 if (h->h_master_sat[i] == CDF_SECID_FREE)
442 #define CDF_SEC_LIMIT (UINT32_MAX / (64 * ss))
443 if ((nsatpersec > 0 &&
444 h->h_num_sectors_in_master_sat > CDF_SEC_LIMIT / nsatpersec) ||
446 DPRINTF(("Number of sectors in master SAT too big %u %"
447 SIZE_T_FORMAT "u\n", h->h_num_sectors_in_master_sat, i));
452 sat->sat_len = h->h_num_sectors_in_master_sat * nsatpersec + i;
453 DPRINTF(("sat_len = %" SIZE_T_FORMAT "u ss = %" SIZE_T_FORMAT "u\n",
455 if ((sat->sat_tab = CAST(cdf_secid_t *, CDF_CALLOC(sat->sat_len, ss)))
459 for (i = 0; i < __arraycount(h->h_master_sat); i++) {
460 if (h->h_master_sat[i] < 0)
462 if (cdf_read_sector(info, sat->sat_tab, ss * i, ss, h,
463 h->h_master_sat[i]) != (ssize_t)ss) {
464 DPRINTF(("Reading sector %d", h->h_master_sat[i]));
469 if ((msa = CAST(cdf_secid_t *, CDF_CALLOC(1, ss))) == NULL)
472 mid = h->h_secid_first_sector_in_master_sat;
473 for (j = 0; j < h->h_num_sectors_in_master_sat; j++) {
476 if (j >= CDF_LOOP_LIMIT) {
477 DPRINTF(("Reading master sector loop limit"));
480 if (cdf_read_sector(info, msa, 0, ss, h, mid) != (ssize_t)ss) {
481 DPRINTF(("Reading master sector %d", mid));
484 for (k = 0; k < nsatpersec; k++, i++) {
485 sec = CDF_TOLE4((uint32_t)msa[k]);
488 if (i >= sat->sat_len) {
489 DPRINTF(("Out of bounds reading MSA %" SIZE_T_FORMAT
490 "u >= %" SIZE_T_FORMAT "u", i, sat->sat_len));
493 if (cdf_read_sector(info, sat->sat_tab, ss * i, ss, h,
494 sec) != (ssize_t)ss) {
495 DPRINTF(("Reading sector %d",
500 mid = CDF_TOLE4((uint32_t)msa[nsatpersec]);
516 cdf_count_chain(const cdf_sat_t *sat, cdf_secid_t sid, size_t size)
519 cdf_secid_t maxsector = (cdf_secid_t)((sat->sat_len * size)
520 / sizeof(maxsector));
523 if (sid == CDF_SECID_END_OF_CHAIN) {
524 /* 0-length chain. */
525 DPRINTF((" empty\n"));
529 for (j = i = 0; sid >= 0; i++, j++) {
530 DPRINTF((" %d", sid));
531 if (j >= CDF_LOOP_LIMIT) {
532 DPRINTF(("Counting chain loop limit"));
535 if (sid >= maxsector) {
536 DPRINTF(("Sector %d >= %d\n", sid, maxsector));
539 sid = CDF_TOLE4((uint32_t)sat->sat_tab[sid]);
542 DPRINTF((" none, sid: %d\n", sid));
554 cdf_read_long_sector_chain(const cdf_info_t *info, const cdf_header_t *h,
555 const cdf_sat_t *sat, cdf_secid_t sid, size_t len, cdf_stream_t *scn)
557 size_t ss = CDF_SEC_SIZE(h), i, j;
560 scn->sst_len = cdf_count_chain(sat, sid, ss);
561 scn->sst_dirlen = MAX(h->h_min_size_standard_stream, len);
564 if (sid == CDF_SECID_END_OF_CHAIN || len == 0)
565 return cdf_zero_stream(scn);
567 if (scn->sst_len == (size_t)-1)
570 scn->sst_tab = CDF_CALLOC(scn->sst_len, ss);
571 if (scn->sst_tab == NULL)
572 return cdf_zero_stream(scn);
574 for (j = i = 0; sid >= 0; i++, j++) {
575 if (j >= CDF_LOOP_LIMIT) {
576 DPRINTF(("Read long sector chain loop limit"));
579 if (i >= scn->sst_len) {
580 DPRINTF(("Out of bounds reading long sector chain "
581 "%" SIZE_T_FORMAT "u > %" SIZE_T_FORMAT "u\n", i,
585 if ((nr = cdf_read_sector(info, scn->sst_tab, i * ss, ss, h,
586 sid)) != (ssize_t)ss) {
587 if (i == scn->sst_len - 1 && nr > 0) {
588 /* Last sector might be truncated */
591 DPRINTF(("Reading long sector chain %d", sid));
594 sid = CDF_TOLE4((uint32_t)sat->sat_tab[sid]);
599 return cdf_zero_stream(scn);
603 cdf_read_short_sector_chain(const cdf_header_t *h,
604 const cdf_sat_t *ssat, const cdf_stream_t *sst,
605 cdf_secid_t sid, size_t len, cdf_stream_t *scn)
607 size_t ss = CDF_SHORT_SEC_SIZE(h), i, j;
609 scn->sst_len = cdf_count_chain(ssat, sid, CDF_SEC_SIZE(h));
610 scn->sst_dirlen = len;
613 if (scn->sst_len == (size_t)-1)
616 scn->sst_tab = CDF_CALLOC(scn->sst_len, ss);
617 if (scn->sst_tab == NULL)
618 return cdf_zero_stream(scn);
620 for (j = i = 0; sid >= 0; i++, j++) {
621 if (j >= CDF_LOOP_LIMIT) {
622 DPRINTF(("Read short sector chain loop limit"));
625 if (i >= scn->sst_len) {
626 DPRINTF(("Out of bounds reading short sector chain "
627 "%" SIZE_T_FORMAT "u > %" SIZE_T_FORMAT "u\n",
631 if (cdf_read_short_sector(sst, scn->sst_tab, i * ss, ss, h,
632 sid) != (ssize_t)ss) {
633 DPRINTF(("Reading short sector chain %d", sid));
636 sid = CDF_TOLE4((uint32_t)ssat->sat_tab[sid]);
641 return cdf_zero_stream(scn);
645 cdf_read_sector_chain(const cdf_info_t *info, const cdf_header_t *h,
646 const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst,
647 cdf_secid_t sid, size_t len, cdf_stream_t *scn)
650 if (len < h->h_min_size_standard_stream && sst->sst_tab != NULL)
651 return cdf_read_short_sector_chain(h, ssat, sst, sid, len,
654 return cdf_read_long_sector_chain(info, h, sat, sid, len, scn);
658 cdf_read_dir(const cdf_info_t *info, const cdf_header_t *h,
659 const cdf_sat_t *sat, cdf_dir_t *dir)
662 size_t ss = CDF_SEC_SIZE(h), ns, nd;
664 cdf_secid_t sid = h->h_secid_first_directory;
666 ns = cdf_count_chain(sat, sid, ss);
667 if (ns == (size_t)-1)
670 nd = ss / CDF_DIRECTORY_SIZE;
672 dir->dir_len = ns * nd;
673 dir->dir_tab = CAST(cdf_directory_t *,
674 CDF_CALLOC(dir->dir_len, sizeof(dir->dir_tab[0])));
675 if (dir->dir_tab == NULL)
678 if ((buf = CAST(char *, CDF_MALLOC(ss))) == NULL) {
683 for (j = i = 0; i < ns; i++, j++) {
684 if (j >= CDF_LOOP_LIMIT) {
685 DPRINTF(("Read dir loop limit"));
688 if (cdf_read_sector(info, buf, 0, ss, h, sid) != (ssize_t)ss) {
689 DPRINTF(("Reading directory sector %d", sid));
692 for (j = 0; j < nd; j++) {
693 cdf_unpack_dir(&dir->dir_tab[i * nd + j],
694 &buf[j * CDF_DIRECTORY_SIZE]);
696 sid = CDF_TOLE4((uint32_t)sat->sat_tab[sid]);
699 for (i = 0; i < dir->dir_len; i++)
700 cdf_swap_dir(&dir->dir_tab[i]);
712 cdf_read_ssat(const cdf_info_t *info, const cdf_header_t *h,
713 const cdf_sat_t *sat, cdf_sat_t *ssat)
716 size_t ss = CDF_SEC_SIZE(h);
717 cdf_secid_t sid = h->h_secid_first_sector_in_short_sat;
719 ssat->sat_tab = NULL;
720 ssat->sat_len = cdf_count_chain(sat, sid, ss);
721 if (ssat->sat_len == (size_t)-1)
724 ssat->sat_tab = CAST(cdf_secid_t *, CDF_CALLOC(ssat->sat_len, ss));
725 if (ssat->sat_tab == NULL)
728 for (j = i = 0; sid >= 0; i++, j++) {
729 if (j >= CDF_LOOP_LIMIT) {
730 DPRINTF(("Read short sat sector loop limit"));
733 if (i >= ssat->sat_len) {
734 DPRINTF(("Out of bounds reading short sector chain "
735 "%" SIZE_T_FORMAT "u > %" SIZE_T_FORMAT "u\n", i,
739 if (cdf_read_sector(info, ssat->sat_tab, i * ss, ss, h, sid) !=
741 DPRINTF(("Reading short sat sector %d", sid));
744 sid = CDF_TOLE4((uint32_t)sat->sat_tab[sid]);
755 cdf_read_short_stream(const cdf_info_t *info, const cdf_header_t *h,
756 const cdf_sat_t *sat, const cdf_dir_t *dir, cdf_stream_t *scn,
757 const cdf_directory_t **root)
760 const cdf_directory_t *d;
763 for (i = 0; i < dir->dir_len; i++)
764 if (dir->dir_tab[i].d_type == CDF_DIR_TYPE_ROOT_STORAGE)
767 /* If the it is not there, just fake it; some docs don't have it */
768 if (i == dir->dir_len) {
769 DPRINTF(("Cannot find root storage dir\n"));
772 d = &dir->dir_tab[i];
775 /* If the it is not there, just fake it; some docs don't have it */
776 if (d->d_stream_first_sector < 0) {
777 DPRINTF(("No first secror in dir\n"));
781 return cdf_read_long_sector_chain(info, h, sat,
782 d->d_stream_first_sector, d->d_size, scn);
785 (void)cdf_zero_stream(scn);
790 cdf_namecmp(const char *d, const uint16_t *s, size_t l)
792 for (; l--; d++, s++)
793 if (*d != CDF_TOLE2(*s))
794 return (unsigned char)*d - CDF_TOLE2(*s);
799 cdf_read_doc_summary_info(const cdf_info_t *info, const cdf_header_t *h,
800 const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst,
801 const cdf_dir_t *dir, cdf_stream_t *scn)
803 return cdf_read_user_stream(info, h, sat, ssat, sst, dir,
804 "\05DocumentSummaryInformation", scn);
808 cdf_read_summary_info(const cdf_info_t *info, const cdf_header_t *h,
809 const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst,
810 const cdf_dir_t *dir, cdf_stream_t *scn)
812 return cdf_read_user_stream(info, h, sat, ssat, sst, dir,
813 "\05SummaryInformation", scn);
817 cdf_read_user_stream(const cdf_info_t *info, const cdf_header_t *h,
818 const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst,
819 const cdf_dir_t *dir, const char *name, cdf_stream_t *scn)
821 const cdf_directory_t *d;
822 int i = cdf_find_stream(dir, name, CDF_DIR_TYPE_USER_STREAM);
825 memset(scn, 0, sizeof(*scn));
829 d = &dir->dir_tab[i - 1];
830 return cdf_read_sector_chain(info, h, sat, ssat, sst,
831 d->d_stream_first_sector, d->d_size, scn);
835 cdf_find_stream(const cdf_dir_t *dir, const char *name, int type)
837 size_t i, name_len = strlen(name) + 1;
839 for (i = dir->dir_len; i > 0; i--)
840 if (dir->dir_tab[i - 1].d_type == type &&
841 cdf_namecmp(name, dir->dir_tab[i - 1].d_name, name_len)
847 DPRINTF(("Cannot find type %d `%s'\n", type, name));
852 #define CDF_SHLEN_LIMIT (UINT32_MAX / 64)
853 #define CDF_PROP_LIMIT (UINT32_MAX / (64 * sizeof(cdf_property_info_t)))
856 cdf_offset(const void *p, size_t l)
858 return CAST(const void *, CAST(const uint8_t *, p) + l);
861 static const uint8_t *
862 cdf_get_property_info_pos(const cdf_stream_t *sst, const cdf_header_t *h,
863 const uint8_t *p, const uint8_t *e, size_t i)
865 size_t tail = (i << 1) + 1;
870 DPRINTF(("Past end %p < %p\n", e, p));
873 if (cdf_check_stream_offset(sst, h, p, (tail + 1) * sizeof(uint32_t),
876 ofs = CDF_GETUINT32(p, tail);
877 q = CAST(const uint8_t *, cdf_offset(CAST(const void *, p),
878 ofs - 2 * sizeof(uint32_t)));
881 DPRINTF(("Wrapped around %p < %p\n", q, p));
886 DPRINTF(("Ran off the end %p >= %p\n", q, e));
892 static cdf_property_info_t *
893 cdf_grow_info(cdf_property_info_t **info, size_t *maxcount, size_t incr)
895 cdf_property_info_t *inp;
896 size_t newcount = *maxcount + incr;
898 if (newcount > CDF_PROP_LIMIT) {
899 DPRINTF(("exceeded property limit %zu > %zu\n",
900 newcount, CDF_PROP_LIMIT));
903 inp = CAST(cdf_property_info_t *,
904 CDF_REALLOC(*info, newcount * sizeof(*inp)));
909 *maxcount = newcount;
919 cdf_copy_info(cdf_property_info_t *inp, const void *p, const void *e,
922 if (inp->pi_type & CDF_VECTOR)
925 if ((size_t)(CAST(const char *, e) - CAST(const char *, p)) < len)
928 (void)memcpy(&inp->pi_val, p, len);
932 inp->pi_u16 = CDF_TOLE2(inp->pi_u16);
935 inp->pi_u32 = CDF_TOLE4(inp->pi_u32);
938 inp->pi_u64 = CDF_TOLE8(inp->pi_u64);
947 cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
948 uint32_t offs, cdf_property_info_t **info, size_t *count, size_t *maxcount)
950 const cdf_section_header_t *shp;
951 cdf_section_header_t sh;
952 const uint8_t *p, *q, *e;
953 size_t i, o4, nelements, j, slen, left;
954 cdf_property_info_t *inp;
956 if (offs > UINT32_MAX / 4) {
960 shp = CAST(const cdf_section_header_t *,
961 cdf_offset(sst->sst_tab, offs));
962 if (cdf_check_stream_offset(sst, h, shp, sizeof(*shp), __LINE__) == -1)
964 sh.sh_len = CDF_TOLE4(shp->sh_len);
965 if (sh.sh_len > CDF_SHLEN_LIMIT) {
970 if (cdf_check_stream_offset(sst, h, shp, sh.sh_len, __LINE__) == -1)
973 sh.sh_properties = CDF_TOLE4(shp->sh_properties);
974 DPRINTF(("section len: %u properties %u\n", sh.sh_len,
976 if (sh.sh_properties > CDF_PROP_LIMIT)
978 inp = cdf_grow_info(info, maxcount, sh.sh_properties);
982 *count += sh.sh_properties;
983 p = CAST(const uint8_t *, cdf_offset(sst->sst_tab, offs + sizeof(sh)));
984 e = CAST(const uint8_t *, cdf_offset(shp, sh.sh_len));
985 if (p >= e || cdf_check_stream_offset(sst, h, e, 0, __LINE__) == -1)
988 for (i = 0; i < sh.sh_properties; i++) {
989 if ((q = cdf_get_property_info_pos(sst, h, p, e, i)) == NULL)
991 inp[i].pi_id = CDF_GETUINT32(p, i << 1);
992 left = CAST(size_t, e - q);
993 if (left < sizeof(uint32_t)) {
994 DPRINTF(("short info (no type)_\n"));
997 inp[i].pi_type = CDF_GETUINT32(q, 0);
998 DPRINTF(("%" SIZE_T_FORMAT "u) id=%#x type=%#x offs=%#tx,%#x\n",
999 i, inp[i].pi_id, inp[i].pi_type, q - p, offs));
1000 if (inp[i].pi_type & CDF_VECTOR) {
1001 if (left < sizeof(uint32_t) * 2) {
1002 DPRINTF(("missing CDF_VECTOR length\n"));
1005 nelements = CDF_GETUINT32(q, 1);
1006 if (nelements == 0) {
1007 DPRINTF(("CDF_VECTOR with nelements == 0\n"));
1015 o4 = slen * sizeof(uint32_t);
1016 if (inp[i].pi_type & (CDF_ARRAY|CDF_BYREF|CDF_RESERVED))
1018 switch (inp[i].pi_type & CDF_TYPEMASK) {
1023 if (!cdf_copy_info(&inp[i], &q[o4], e, sizeof(int16_t)))
1028 case CDF_UNSIGNED32:
1030 if (!cdf_copy_info(&inp[i], &q[o4], e, sizeof(int32_t)))
1034 case CDF_UNSIGNED64:
1037 if (!cdf_copy_info(&inp[i], &q[o4], e, sizeof(int64_t)))
1040 case CDF_LENGTH32_STRING:
1041 case CDF_LENGTH32_WSTRING:
1042 if (nelements > 1) {
1043 size_t nelem = inp - *info;
1044 inp = cdf_grow_info(info, maxcount, nelements);
1049 DPRINTF(("nelements = %" SIZE_T_FORMAT "u\n",
1051 for (j = 0; j < nelements && i < sh.sh_properties;
1056 if (o4 + sizeof(uint32_t) > left)
1059 l = CDF_GETUINT32(q, slen);
1060 o4 += sizeof(uint32_t);
1064 inp[i].pi_str.s_len = l;
1065 inp[i].pi_str.s_buf = CAST(const char *,
1066 CAST(const void *, &q[o4]));
1068 DPRINTF(("o=%zu l=%d(%" SIZE_T_FORMAT
1069 "u), t=%zu s=%s\n", o4, l,
1070 CDF_ROUND(l, sizeof(l)), left,
1071 inp[i].pi_str.s_buf));
1077 o4 = slen * sizeof(uint32_t);
1082 if (inp[i].pi_type & CDF_VECTOR)
1087 memset(&inp[i].pi_val, 0, sizeof(inp[i].pi_val));
1088 DPRINTF(("Don't know how to deal with %#x\n",
1104 cdf_unpack_summary_info(const cdf_stream_t *sst, const cdf_header_t *h,
1105 cdf_summary_info_header_t *ssi, cdf_property_info_t **info, size_t *count)
1108 const cdf_summary_info_header_t *si =
1109 CAST(const cdf_summary_info_header_t *, sst->sst_tab);
1110 const cdf_section_declaration_t *sd =
1111 CAST(const cdf_section_declaration_t *, (const void *)
1112 ((const char *)sst->sst_tab + CDF_SECTION_DECLARATION_OFFSET));
1114 if (cdf_check_stream_offset(sst, h, si, sizeof(*si), __LINE__) == -1 ||
1115 cdf_check_stream_offset(sst, h, sd, sizeof(*sd), __LINE__) == -1)
1117 ssi->si_byte_order = CDF_TOLE2(si->si_byte_order);
1118 ssi->si_os_version = CDF_TOLE2(si->si_os_version);
1119 ssi->si_os = CDF_TOLE2(si->si_os);
1120 ssi->si_class = si->si_class;
1121 cdf_swap_class(&ssi->si_class);
1122 ssi->si_count = CDF_TOLE4(si->si_count);
1126 if (cdf_read_property_info(sst, h, CDF_TOLE4(sd->sd_offset), info,
1127 count, &maxcount) == -1)
1133 #define extract_catalog_field(t, f, l) \
1134 if (b + l + sizeof(cep->f) > eb) { \
1135 cep->ce_namlen = 0; \
1138 memcpy(&cep->f, b + (l), sizeof(cep->f)); \
1139 ce[i].f = CAST(t, CDF_TOLE(cep->f))
1142 cdf_unpack_catalog(const cdf_header_t *h, const cdf_stream_t *sst,
1143 cdf_catalog_t **cat)
1145 size_t ss = cdf_check_stream(sst, h);
1146 const char *b = CAST(const char *, sst->sst_tab);
1147 const char *nb, *eb = b + ss * sst->sst_len;
1149 cdf_catalog_entry_t *ce;
1153 for (nr = 0;; nr++) {
1154 memcpy(&reclen, b, sizeof(reclen));
1155 reclen = CDF_TOLE2(reclen);
1165 *cat = CAST(cdf_catalog_t *,
1166 CDF_MALLOC(sizeof(cdf_catalog_t) + nr * sizeof(*ce)));
1170 memset(ce, 0, nr * sizeof(*ce));
1171 b = CAST(const char *, sst->sst_tab);
1172 for (j = i = 0; i < nr; b += reclen) {
1173 cdf_catalog_entry_t *cep = &ce[j];
1176 extract_catalog_field(uint16_t, ce_namlen, 0);
1177 extract_catalog_field(uint16_t, ce_num, 4);
1178 extract_catalog_field(uint64_t, ce_timestamp, 8);
1179 reclen = cep->ce_namlen;
1186 cep->ce_namlen = __arraycount(cep->ce_name) - 1;
1188 if (cep->ce_namlen > rlen)
1189 cep->ce_namlen = rlen;
1191 np = CAST(const uint16_t *, CAST(const void *, (b + 16)));
1192 nb = CAST(const char *, CAST(const void *,
1193 (np + cep->ce_namlen)));
1199 for (k = 0; k < cep->ce_namlen; k++)
1200 cep->ce_name[k] = np[k]; /* XXX: CDF_TOLE2? */
1201 cep->ce_name[cep->ce_namlen] = 0;
1205 (*cat)->cat_num = j;
1210 cdf_print_classid(char *buf, size_t buflen, const cdf_classid_t *id)
1212 return snprintf(buf, buflen, "%.8x-%.4x-%.4x-%.2x%.2x-"
1213 "%.2x%.2x%.2x%.2x%.2x%.2x", id->cl_dword, id->cl_word[0],
1214 id->cl_word[1], id->cl_two[0], id->cl_two[1], id->cl_six[0],
1215 id->cl_six[1], id->cl_six[2], id->cl_six[3], id->cl_six[4],
1219 static const struct {
1223 { CDF_PROPERTY_CODE_PAGE, "Code page" },
1224 { CDF_PROPERTY_TITLE, "Title" },
1225 { CDF_PROPERTY_SUBJECT, "Subject" },
1226 { CDF_PROPERTY_AUTHOR, "Author" },
1227 { CDF_PROPERTY_KEYWORDS, "Keywords" },
1228 { CDF_PROPERTY_COMMENTS, "Comments" },
1229 { CDF_PROPERTY_TEMPLATE, "Template" },
1230 { CDF_PROPERTY_LAST_SAVED_BY, "Last Saved By" },
1231 { CDF_PROPERTY_REVISION_NUMBER, "Revision Number" },
1232 { CDF_PROPERTY_TOTAL_EDITING_TIME, "Total Editing Time" },
1233 { CDF_PROPERTY_LAST_PRINTED, "Last Printed" },
1234 { CDF_PROPERTY_CREATE_TIME, "Create Time/Date" },
1235 { CDF_PROPERTY_LAST_SAVED_TIME, "Last Saved Time/Date" },
1236 { CDF_PROPERTY_NUMBER_OF_PAGES, "Number of Pages" },
1237 { CDF_PROPERTY_NUMBER_OF_WORDS, "Number of Words" },
1238 { CDF_PROPERTY_NUMBER_OF_CHARACTERS, "Number of Characters" },
1239 { CDF_PROPERTY_THUMBNAIL, "Thumbnail" },
1240 { CDF_PROPERTY_NAME_OF_APPLICATION, "Name of Creating Application" },
1241 { CDF_PROPERTY_SECURITY, "Security" },
1242 { CDF_PROPERTY_LOCALE_ID, "Locale ID" },
1246 cdf_print_property_name(char *buf, size_t bufsiz, uint32_t p)
1250 for (i = 0; i < __arraycount(vn); i++)
1252 return snprintf(buf, bufsiz, "%s", vn[i].n);
1253 return snprintf(buf, bufsiz, "%#x", p);
1257 cdf_print_elapsed_time(char *buf, size_t bufsiz, cdf_timestamp_t ts)
1260 int days, hours, mins, secs;
1262 ts /= CDF_TIME_PREC;
1263 secs = (int)(ts % 60);
1265 mins = (int)(ts % 60);
1267 hours = (int)(ts % 24);
1272 len += snprintf(buf + len, bufsiz - len, "%dd+", days);
1273 if ((size_t)len >= bufsiz)
1277 if (days || hours) {
1278 len += snprintf(buf + len, bufsiz - len, "%.2d:", hours);
1279 if ((size_t)len >= bufsiz)
1283 len += snprintf(buf + len, bufsiz - len, "%.2d:", mins);
1284 if ((size_t)len >= bufsiz)
1287 len += snprintf(buf + len, bufsiz - len, "%.2d", secs);
1292 cdf_u16tos8(char *buf, size_t len, const uint16_t *p)
1295 for (i = 0; i < len && p[i]; i++)
1296 buf[i] = (char)p[i];
1303 cdf_dump_header(const cdf_header_t *h)
1307 #define DUMP(a, b) (void)fprintf(stderr, "%40.40s = " a "\n", # b, h->h_ ## b)
1308 #define DUMP2(a, b) (void)fprintf(stderr, "%40.40s = " a " (" a ")\n", # b, \
1309 h->h_ ## b, 1 << h->h_ ## b)
1310 DUMP("%d", revision);
1311 DUMP("%d", version);
1312 DUMP("%#x", byte_order);
1313 DUMP2("%d", sec_size_p2);
1314 DUMP2("%d", short_sec_size_p2);
1315 DUMP("%d", num_sectors_in_sat);
1316 DUMP("%d", secid_first_directory);
1317 DUMP("%d", min_size_standard_stream);
1318 DUMP("%d", secid_first_sector_in_short_sat);
1319 DUMP("%d", num_sectors_in_short_sat);
1320 DUMP("%d", secid_first_sector_in_master_sat);
1321 DUMP("%d", num_sectors_in_master_sat);
1322 for (i = 0; i < __arraycount(h->h_master_sat); i++) {
1323 if (h->h_master_sat[i] == CDF_SECID_FREE)
1325 (void)fprintf(stderr, "%35.35s[%.3" SIZE_T_FORMAT "u] = %d\n",
1326 "master_sat", i, h->h_master_sat[i]);
1331 cdf_dump_sat(const char *prefix, const cdf_sat_t *sat, size_t size)
1333 size_t i, j, s = size / sizeof(cdf_secid_t);
1335 for (i = 0; i < sat->sat_len; i++) {
1336 (void)fprintf(stderr, "%s[%" SIZE_T_FORMAT "u]:\n%.6"
1337 SIZE_T_FORMAT "u: ", prefix, i, i * s);
1338 for (j = 0; j < s; j++) {
1339 (void)fprintf(stderr, "%5d, ",
1340 CDF_TOLE4(sat->sat_tab[s * i + j]));
1341 if ((j + 1) % 10 == 0)
1342 (void)fprintf(stderr, "\n%.6" SIZE_T_FORMAT
1343 "u: ", i * s + j + 1);
1345 (void)fprintf(stderr, "\n");
1350 cdf_dump(const void *v, size_t len)
1353 const unsigned char *p = v;
1356 (void)fprintf(stderr, "%.4x: ", 0);
1357 for (i = 0, j = 0; i < len; i++, p++) {
1358 (void)fprintf(stderr, "%.2x ", *p);
1359 abuf[j++] = isprint(*p) ? *p : '.';
1363 (void)fprintf(stderr, "%s\n%.4" SIZE_T_FORMAT "x: ",
1367 (void)fprintf(stderr, "\n");
1371 cdf_dump_stream(const cdf_stream_t *sst)
1373 size_t ss = sst->sst_ss;
1374 cdf_dump(sst->sst_tab, ss * sst->sst_len);
1378 cdf_dump_dir(const cdf_info_t *info, const cdf_header_t *h,
1379 const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst,
1380 const cdf_dir_t *dir)
1384 char name[__arraycount(d->d_name)];
1388 static const char *types[] = { "empty", "user storage",
1389 "user stream", "lockbytes", "property", "root storage" };
1391 for (i = 0; i < dir->dir_len; i++) {
1393 d = &dir->dir_tab[i];
1394 for (j = 0; j < sizeof(name); j++)
1395 name[j] = (char)CDF_TOLE2(d->d_name[j]);
1396 (void)fprintf(stderr, "Directory %" SIZE_T_FORMAT "u: %s\n",
1398 if (d->d_type < __arraycount(types))
1399 (void)fprintf(stderr, "Type: %s\n", types[d->d_type]);
1401 (void)fprintf(stderr, "Type: %d\n", d->d_type);
1402 (void)fprintf(stderr, "Color: %s\n",
1403 d->d_color ? "black" : "red");
1404 (void)fprintf(stderr, "Left child: %d\n", d->d_left_child);
1405 (void)fprintf(stderr, "Right child: %d\n", d->d_right_child);
1406 (void)fprintf(stderr, "Flags: %#x\n", d->d_flags);
1407 cdf_timestamp_to_timespec(&ts, d->d_created);
1408 (void)fprintf(stderr, "Created %s", cdf_ctime(&ts.tv_sec, buf));
1409 cdf_timestamp_to_timespec(&ts, d->d_modified);
1410 (void)fprintf(stderr, "Modified %s",
1411 cdf_ctime(&ts.tv_sec, buf));
1412 (void)fprintf(stderr, "Stream %d\n", d->d_stream_first_sector);
1413 (void)fprintf(stderr, "Size %d\n", d->d_size);
1414 switch (d->d_type) {
1415 case CDF_DIR_TYPE_USER_STORAGE:
1416 (void)fprintf(stderr, "Storage: %d\n", d->d_storage);
1418 case CDF_DIR_TYPE_USER_STREAM:
1421 if (cdf_read_sector_chain(info, h, sat, ssat, sst,
1422 d->d_stream_first_sector, d->d_size, &scn) == -1) {
1423 warn("Can't read stream for %s at %d len %d",
1424 name, d->d_stream_first_sector, d->d_size);
1427 cdf_dump_stream(&scn);
1438 cdf_dump_property_info(const cdf_property_info_t *info, size_t count)
1445 for (i = 0; i < count; i++) {
1446 cdf_print_property_name(buf, sizeof(buf), info[i].pi_id);
1447 (void)fprintf(stderr, "%" SIZE_T_FORMAT "u) %s: ", i, buf);
1448 switch (info[i].pi_type) {
1452 (void)fprintf(stderr, "signed 16 [%hd]\n",
1456 (void)fprintf(stderr, "signed 32 [%d]\n",
1459 case CDF_UNSIGNED32:
1460 (void)fprintf(stderr, "unsigned 32 [%u]\n",
1464 (void)fprintf(stderr, "float [%g]\n",
1468 (void)fprintf(stderr, "double [%g]\n",
1471 case CDF_LENGTH32_STRING:
1472 (void)fprintf(stderr, "string %u [%.*s]\n",
1473 info[i].pi_str.s_len,
1474 info[i].pi_str.s_len, info[i].pi_str.s_buf);
1476 case CDF_LENGTH32_WSTRING:
1477 (void)fprintf(stderr, "string %u [",
1478 info[i].pi_str.s_len);
1479 for (j = 0; j < info[i].pi_str.s_len - 1; j++)
1480 (void)fputc(info[i].pi_str.s_buf[j << 1], stderr);
1481 (void)fprintf(stderr, "]\n");
1485 if (tp < 1000000000000000LL) {
1486 cdf_print_elapsed_time(buf, sizeof(buf), tp);
1487 (void)fprintf(stderr, "timestamp %s\n", buf);
1490 cdf_timestamp_to_timespec(&ts, tp);
1491 (void)fprintf(stderr, "timestamp %s",
1492 cdf_ctime(&ts.tv_sec, tbuf));
1496 (void)fprintf(stderr, "CLIPBOARD %u\n", info[i].pi_u32);
1499 DPRINTF(("Don't know how to deal with %#x\n",
1508 cdf_dump_summary_info(const cdf_header_t *h, const cdf_stream_t *sst)
1511 cdf_summary_info_header_t ssi;
1512 cdf_property_info_t *info;
1516 if (cdf_unpack_summary_info(sst, h, &ssi, &info, &count) == -1)
1518 (void)fprintf(stderr, "Endian: %#x\n", ssi.si_byte_order);
1519 (void)fprintf(stderr, "Os Version %d.%d\n", ssi.si_os_version & 0xff,
1520 ssi.si_os_version >> 8);
1521 (void)fprintf(stderr, "Os %d\n", ssi.si_os);
1522 cdf_print_classid(buf, sizeof(buf), &ssi.si_class);
1523 (void)fprintf(stderr, "Class %s\n", buf);
1524 (void)fprintf(stderr, "Count %d\n", ssi.si_count);
1525 cdf_dump_property_info(info, count);
1531 cdf_dump_catalog(const cdf_header_t *h, const cdf_stream_t *sst)
1534 cdf_unpack_catalog(h, sst, &cat);
1535 const cdf_catalog_entry_t *ce = cat->cat_e;
1537 char tbuf[64], sbuf[256];
1540 printf("Catalog:\n");
1541 for (i = 0; i < cat->cat_num; i++) {
1542 cdf_timestamp_to_timespec(&ts, ce[i].ce_timestamp);
1543 printf("\t%d %s %s", ce[i].ce_num,
1544 cdf_u16tos8(sbuf, ce[i].ce_namlen, ce[i].ce_name),
1545 cdf_ctime(&ts.tv_sec, tbuf));
1554 main(int argc, char *argv[])
1558 cdf_sat_t sat, ssat;
1559 cdf_stream_t sst, scn;
1562 const cdf_directory_t *root;
1564 #define getprogname() __progname
1565 extern char *__progname;
1568 (void)fprintf(stderr, "Usage: %s <filename>\n", getprogname());
1574 for (i = 1; i < argc; i++) {
1575 if ((info.i_fd = open(argv[1], O_RDONLY)) == -1)
1576 err(EXIT_FAILURE, "Cannot open `%s'", argv[1]);
1578 if (cdf_read_header(&info, &h) == -1)
1579 err(EXIT_FAILURE, "Cannot read header");
1581 cdf_dump_header(&h);
1584 if (cdf_read_sat(&info, &h, &sat) == -1)
1585 err(EXIT_FAILURE, "Cannot read sat");
1587 cdf_dump_sat("SAT", &sat, CDF_SEC_SIZE(&h));
1590 if (cdf_read_ssat(&info, &h, &sat, &ssat) == -1)
1591 err(EXIT_FAILURE, "Cannot read ssat");
1593 cdf_dump_sat("SSAT", &ssat, CDF_SHORT_SEC_SIZE(&h));
1596 if (cdf_read_dir(&info, &h, &sat, &dir) == -1)
1597 err(EXIT_FAILURE, "Cannot read dir");
1599 if (cdf_read_short_stream(&info, &h, &sat, &dir, &sst, &root)
1601 err(EXIT_FAILURE, "Cannot read short stream");
1603 cdf_dump_stream(&sst);
1607 cdf_dump_dir(&info, &h, &sat, &ssat, &sst, &dir);
1611 if (cdf_read_summary_info(&info, &h, &sat, &ssat, &sst, &dir,
1613 warn("Cannot read summary info");
1616 cdf_dump_summary_info(&h, &scn);
1618 if (cdf_read_user_stream(&info, &h, &sat, &ssat, &sst,
1619 &dir, "Catalog", &scn) == -1)
1620 warn("Cannot read catalog");
1623 cdf_dump_catalog(&h, &scn);
1626 (void)close(info.i_fd);