From: Christos Zoulas Date: Wed, 14 May 2014 23:22:48 +0000 (+0000) Subject: PR/352: Support for Hangul (Korean) Word Processor 5.x Files (*.hwp) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=867d8355a55e5f20f748e60d0dc6ed967ae1be0e;p=file PR/352: Support for Hangul (Korean) Word Processor 5.x Files (*.hwp) --- diff --git a/src/cdf.c b/src/cdf.c index 72511670..2049ac09 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.58 2014/05/13 16:41:06 christos Exp $") +FILE_RCSID("@(#)$File: cdf.c,v 1.59 2014/05/14 23:22:48 christos Exp $") #endif #include @@ -723,19 +723,28 @@ int cdf_read_summary_info(const cdf_info_t *info, const cdf_header_t *h, const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst, const cdf_dir_t *dir, cdf_stream_t *scn) +{ + return cdf_read_user_stream(info, h, sat, ssat, sst, dir, + "\05SummaryInformation", scn); +} + +int +cdf_read_user_stream(const cdf_info_t *info, const cdf_header_t *h, + const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst, + const cdf_dir_t *dir, const char *name, cdf_stream_t *scn) { size_t i; const cdf_directory_t *d; - static const char name[] = "\05SummaryInformation"; + size_t name_len = strlen(name) + 1; for (i = dir->dir_len; i > 0; i--) if (dir->dir_tab[i - 1].d_type == CDF_DIR_TYPE_USER_STREAM && - cdf_namecmp(name, dir->dir_tab[i - 1].d_name, sizeof(name)) + cdf_namecmp(name, dir->dir_tab[i - 1].d_name, name_len) == 0) break; if (i == 0) { - DPRINTF(("Cannot find summary information section\n")); + DPRINTF(("Cannot find user stream `%s'\n", name)); errno = ESRCH; return -1; } diff --git a/src/cdf.h b/src/cdf.h index 177868eb..910fb95f 100644 --- a/src/cdf.h +++ b/src/cdf.h @@ -298,6 +298,9 @@ int cdf_read_short_stream(const cdf_info_t *, const cdf_header_t *, const cdf_directory_t **); int cdf_read_property_info(const cdf_stream_t *, const cdf_header_t *, uint32_t, cdf_property_info_t **, size_t *, size_t *); +int cdf_read_user_stream(const cdf_info_t *, const cdf_header_t *, + const cdf_sat_t *, const cdf_sat_t *, const cdf_stream_t *, + const cdf_dir_t *, const char *, cdf_stream_t *); int cdf_read_summary_info(const cdf_info_t *, const cdf_header_t *, const cdf_sat_t *, const cdf_sat_t *, const cdf_stream_t *, const cdf_dir_t *, cdf_stream_t *); diff --git a/src/readcdf.c b/src/readcdf.c index fc5e29a6..7ced9ea6 100644 --- a/src/readcdf.c +++ b/src/readcdf.c @@ -26,7 +26,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: readcdf.c,v 1.43 2014/05/07 21:26:06 christos Exp $") +FILE_RCSID("@(#)$File: readcdf.c,v 1.44 2014/05/14 23:22:48 christos Exp $") #endif #include @@ -137,7 +137,8 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info, int len; if (!NOTMIME(ms) && root_storage) - str = cdf_clsid_to_mime(root_storage->d_storage_uuid, clsid2mime); + str = cdf_clsid_to_mime(root_storage->d_storage_uuid, + clsid2mime); for (i = 0; i < count; i++) { cdf_print_property_name(buf, sizeof(buf), info[i].pi_id); @@ -282,7 +283,8 @@ cdf_file_summary_info(struct magic_set *ms, const cdf_header_t *h, break; } if (root_storage) { - str = cdf_clsid_to_mime(root_storage->d_storage_uuid, clsid2desc); + str = cdf_clsid_to_mime(root_storage->d_storage_uuid, + clsid2desc); if (str) if (file_printf(ms, ", %s", str) == -1) return -2; @@ -375,6 +377,30 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf, } #endif + if ((i = cdf_read_user_stream(&info, &h, &sat, &ssat, &sst, &dir, + "FileHeader", &scn)) != -1) { +#define HWP5_SIGNATURE "HWP Document File" + if (scn.sst_dirlen >= sizeof(HWP5_SIGNATURE) - 1 + && memcmp(scn.sst_tab, HWP5_SIGNATURE, + sizeof(HWP5_SIGNATURE) - 1) == 0) { + if (NOTMIME(ms)) { + if (file_printf(ms, + "Hangul (Korean) Word Processor File 5.x") == -1) + return -1; + } else { + if (file_printf(ms, "application/x-hwp") == -1) + return -1; + } + i = 1; + goto out5; + } else { + free(scn.sst_tab); + scn.sst_tab = NULL; + scn.sst_len = 0; + scn.sst_dirlen = 0; + } + } + if ((i = cdf_read_summary_info(&info, &h, &sat, &ssat, &sst, &dir, &scn)) == -1) { if (errno == ESRCH) { @@ -418,6 +444,7 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf, i = 1; } } +out5: free(scn.sst_tab); out4: free(sst.sst_tab);