]> granicus.if.org Git - file/commitdiff
PR/352: Support for Hangul (Korean) Word Processor 5.x Files (*.hwp)
authorChristos Zoulas <christos@zoulas.com>
Wed, 14 May 2014 23:22:48 +0000 (23:22 +0000)
committerChristos Zoulas <christos@zoulas.com>
Wed, 14 May 2014 23:22:48 +0000 (23:22 +0000)
src/cdf.c
src/cdf.h
src/readcdf.c

index 5ae96acaeef64e36889bee33449d1dbde8ae23a8..48a00ec47cf41c4a2f9da8ee1adca05f29aba363 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.57 2014/05/06 18:20:39 christos Exp $")
+FILE_RCSID("@(#)$File: cdf.c,v 1.58 2014/05/13 16:41:06 christos Exp $")
 #endif
 
 #include <assert.h>
@@ -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;
        }
index 177868eb55ee3dcd19e578d239df2850a647b4ab..910fb95fc34112894433b34b8aeabf3665c30cb5 100644 (file)
--- 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 *);
index fc415218afbeebfc90a3caa8db7d4654e5a77df5..e1b283122b3c9f96038ff3fbbb1cff64b5cef027 100644 (file)
@@ -26,7 +26,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: readcdf.c,v 1.42 2014/05/07 10:13:12 christos Exp $")
+FILE_RCSID("@(#)$File: readcdf.c,v 1.43 2014/05/07 21:26:06 christos Exp $")
 #endif
 
 #include <assert.h>
@@ -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);