summaryrefslogtreecommitdiffstats
path: root/contrib/file/readcdf.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/file/readcdf.c')
-rw-r--r--contrib/file/readcdf.c91
1 files changed, 52 insertions, 39 deletions
diff --git a/contrib/file/readcdf.c b/contrib/file/readcdf.c
index 27031db..15f53fe 100644
--- a/contrib/file/readcdf.c
+++ b/contrib/file/readcdf.c
@@ -26,7 +26,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: readcdf.c,v 1.11 2009/02/03 20:27:51 christos Exp $")
+FILE_RCSID("@(#)$File: readcdf.c,v 1.18 2009/05/06 20:48:22 christos Exp $")
#endif
#include <stdlib.h>
@@ -75,9 +75,23 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
if (len > 1) {
s = info[i].pi_str.s_buf;
if (NOTMIME(ms)) {
- if (file_printf(ms, ", %s: %.*s", buf,
- len, s) == -1)
- return -1;
+ char vbuf[1024];
+ size_t j;
+ for (j = 0; j < sizeof(vbuf) && len--;
+ j++, s++) {
+ if (*s == '\0')
+ break;
+ if (isprint((unsigned char)*s))
+ vbuf[j] = *s;
+ }
+ if (j == sizeof(vbuf))
+ --j;
+ vbuf[j] = '\0';
+ if (vbuf[0]) {
+ if (file_printf(ms, ", %s: %s",
+ buf, vbuf) == -1)
+ return -1;
+ }
} else if (info[i].pi_id ==
CDF_PROPERTY_NAME_OF_APPLICATION) {
if (strstr(s, "Word"))
@@ -115,7 +129,6 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
case CDF_CLIPBOARD:
break;
default:
- file_error(ms, 0, "Internal parsing error");
return -1;
}
}
@@ -134,15 +147,8 @@ cdf_file_summary_info(struct magic_set *ms, const cdf_stream_t *sst)
size_t count;
int m;
- if (cdf_unpack_summary_info(sst, &si, &info, &count) == -1) {
- if (si.si_byte_order != 0xfffe)
- return 0;
- else
- return -1;
- }
-
- if (si.si_byte_order != 0xfffe)
- return 0;
+ if (cdf_unpack_summary_info(sst, &si, &info, &count) == -1)
+ return -1;
if (NOTMIME(ms)) {
if (file_printf(ms, "CDF V2 Document") == -1)
@@ -183,66 +189,64 @@ protected int
file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
size_t nbytes)
{
+ cdf_info_t info;
cdf_header_t h;
cdf_sat_t sat, ssat;
cdf_stream_t sst, scn;
cdf_dir_t dir;
int i;
- (void)&nbytes;
- (void)&buf;
+ const char *expn = "";
+ info.i_fd = fd;
+ info.i_buf = buf;
+ info.i_len = nbytes;
if (ms->flags & MAGIC_APPLE)
return 0;
- if (cdf_read_header(fd, &h) == -1)
+ if (cdf_read_header(&info, &h) == -1)
return 0;
#ifdef CDF_DEBUG
cdf_dump_header(&h);
#endif
- if (cdf_read_sat(fd, &h, &sat) == -1) {
- file_error(ms, errno, "Can't read SAT");
- return -1;
+ if ((i = cdf_read_sat(&info, &h, &sat)) == -1) {
+ expn = "Can't read SAT";
+ goto out0;
}
#ifdef CDF_DEBUG
- cdf_dump_sat("SAT", &h, &sat);
+ cdf_dump_sat("SAT", &sat, CDF_SEC_SIZE(&h));
#endif
- if ((i = cdf_read_ssat(fd, &h, &sat, &ssat)) == -1) {
- file_error(ms, errno, "Can't read SAT");
+ if ((i = cdf_read_ssat(&info, &h, &sat, &ssat)) == -1) {
+ expn = "Can't read SSAT";
goto out1;
}
#ifdef CDF_DEBUG
- cdf_dump_sat("SSAT", &h, &ssat);
+ cdf_dump_sat("SSAT", &ssat, CDF_SHORT_SEC_SIZE(&h));
#endif
- if ((i = cdf_read_dir(fd, &h, &sat, &dir)) == -1) {
- file_error(ms, errno, "Can't read directory");
+ if ((i = cdf_read_dir(&info, &h, &sat, &dir)) == -1) {
+ expn = "Can't read directory";
goto out2;
}
- if ((i = cdf_read_short_stream(fd, &h, &sat, &dir, &sst)) == -1) {
- file_error(ms, errno, "Cannot read short stream");
+ if ((i = cdf_read_short_stream(&info, &h, &sat, &dir, &sst)) == -1) {
+ expn = "Cannot read short stream";
goto out3;
}
-
#ifdef CDF_DEBUG
- cdf_dump_dir(fd, &h, &sat, &ssat, &sst, &dir);
-#endif
- if ((i = cdf_read_summary_info(fd, &h, &sat, &ssat, &sst, &dir, &scn))
- == -1) {
- /* Some files don't have summary info! */
-#ifdef notyet
- file_error(ms, errno, "Can't read summary_info");
-#else
- i = 0;
+ cdf_dump_dir(&info, &h, &sat, &ssat, &sst, &dir);
#endif
+
+ if ((i = cdf_read_summary_info(&info, &h, &sat, &ssat, &sst, &dir,
+ &scn)) == -1) {
+ expn = "Cannot read summary info";
goto out4;
}
#ifdef CDF_DEBUG
cdf_dump_summary_info(&h, &scn);
#endif
if ((i = cdf_file_summary_info(ms, &scn)) == -1)
- file_error(ms, errno, "Can't expand summary_info");
+ expn = "Can't expand summary_info";
free(scn.sst_tab);
out4:
free(sst.sst_tab);
@@ -252,5 +256,14 @@ out2:
free(ssat.sat_tab);
out1:
free(sat.sat_tab);
+out0:
+ if (i != 1) {
+ if (file_printf(ms, "CDF V2 Document") == -1)
+ return -1;
+ if (*expn)
+ if (file_printf(ms, ", corrupt: %s", expn) == -1)
+ return -1;
+ i = 1;
+ }
return i;
}
OpenPOWER on IntegriCloud