[libgsf] ole: fix property writing



commit 1f5066901428c7bfa11cae30b9c4e477b6f0d815
Author: Morten Welinder <terra gnome org>
Date:   Sun Dec 16 12:43:02 2018 -0500

    ole: fix property writing

 ChangeLog                 |  7 +++++++
 NEWS                      |  3 +++
 gsf/gsf-doc-meta-data.c   |  2 +-
 gsf/gsf-libxml.c          |  2 +-
 gsf/gsf-msole-utils.c     | 29 ++++++++++++++---------------
 gsf/gsf-structured-blob.c |  6 +++---
 6 files changed, 29 insertions(+), 20 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 987dddd..5a37296 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2018-12-16  Morten Welinder  <terra gnome org>
+
+       * gsf/gsf-msole-utils.c (msole_prop_parse): Don't convert the
+       terminator.
+       (msole_metadata_write_section): Don't seek beyond end of stream --
+       use plain writes instead.  Fixes #14.
+
 2018-08-08  Morten Welinder <terra gnome org>
 
        * configure.ac: Post-release bump.
diff --git a/NEWS b/NEWS
index 3cbd825..d79f122 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
 libgsf 1.14.45
 
+Morten:
+       * Fix problem with ole property writing.  [#14]
+
 --------------------------------------------------------------------------
 libgsf 1.14.44
 
diff --git a/gsf/gsf-doc-meta-data.c b/gsf/gsf-doc-meta-data.c
index b0b4ac8..ddcb500 100644
--- a/gsf/gsf-doc-meta-data.c
+++ b/gsf/gsf-doc-meta-data.c
@@ -436,7 +436,7 @@ gsf_doc_prop_set_link (GsfDocProp *prop, char *link)
 void
 gsf_doc_prop_dump (GsfDocProp const *prop)
 {
-       GValue const *val = gsf_doc_prop_get_val  (prop);
+       GValue const *val = gsf_doc_prop_get_val (prop);
        char *tmp;
        if (VAL_IS_GSF_DOCPROP_VECTOR ((GValue *)val)) {
                GValueArray *va = gsf_value_get_docprop_varray (val);
diff --git a/gsf/gsf-libxml.c b/gsf/gsf-libxml.c
index 29bfa6d..a8449bb 100644
--- a/gsf/gsf-libxml.c
+++ b/gsf/gsf-libxml.c
@@ -760,7 +760,7 @@ gsf_xml_in_start_element (GsfXMLInInternal *state, xmlChar const *name, xmlChar
                                        g_hash_table_insert (state->ns_prefixes, g_strdup (ns_ptr[0] + 6), 
inst);
 
                                        if (ns[i].ns_id >= state->ns_by_id->len)
-                                               g_ptr_array_set_size  (state->ns_by_id, ns[i].ns_id+1);
+                                               g_ptr_array_set_size (state->ns_by_id, ns[i].ns_id+1);
                                        if (g_ptr_array_index (state->ns_by_id, ns[i].ns_id)) {
                                                g_warning ("Damn.  Someone just declared the same namespace 
'%s' with a different prefix '%s'",
                                                           ns[i].uri, inst->tag);
diff --git a/gsf/gsf-msole-utils.c b/gsf/gsf-msole-utils.c
index f6a1c33..c8e61a9 100644
--- a/gsf/gsf-msole-utils.c
+++ b/gsf/gsf-msole-utils.c
@@ -751,7 +751,7 @@ msole_prop_parse (GsfMSOleMetaDataSection *section,
                error = NULL;
                d (gsf_mem_dump (*data, len * section->char_size););
                str = g_convert_with_iconv (*data,
-                       len, // That includes the 0x00 or 0x0000 -- probably ok
+                                           len > section->char_size ? len - section->char_size : 0,
                        section->iconv_handle, NULL, NULL, &error);
 
                g_value_init (res, G_TYPE_STRING);
@@ -1052,7 +1052,7 @@ msole_prop_read (GsfInput *in,
                        /* MS documentation blows goats !
                         * The docs claim there are padding bytes in the dictionary.
                         * Their examples show padding bytes.
-                        * In reality non-unicode strings do not seem to 
+                        * In reality non-unicode strings do not seem to
                         * have padding.
                         */
                        if (section->char_size != 1 && (data - start) % 4)
@@ -1576,39 +1576,38 @@ msole_metadata_write_section (WritePropState *state, gboolean user)
        if (user && state->dict == NULL)
                return TRUE;
 
-       /* Skip past the size and id/offset pairs */
-       if (!gsf_output_seek (state->out,
-                            4 /* length */ +
-                            4 /* count */ +
-                            8 * count /* id/offset pairs */,
-                            G_SEEK_END))
-               return FALSE;
+       // Skip past the size+count and id/offset pairs
+       GSF_LE_SET_GUINT32 (buf, 0);
+       for (i = 0; i < 1 + 1 + 2 * count; i++)
+               gsf_output_write (state->out, 4, buf);
 
        memset (&scratch,  0, sizeof (GValue));
        g_value_init (&scratch, G_TYPE_STRING);
 
        offsets = g_alloca (sizeof (GsfMSOleMetaDataProp) * count);
 
+       i = 0;
+
        /* 0) codepage */
-       if (count >= 1) {
+       if (i < count) {
                offsets[0].id = 1;
                offsets[0].offset = gsf_output_tell (state->out);
                GSF_LE_SET_GUINT32 (buf, VT_I2);
                GSF_LE_SET_GUINT32 (buf+4, state->codepage);
                gsf_output_write (state->out, 8, buf);
+               i++;
        }
 
        /* 1) dictionary */
-       if (user && count >= 2) {
+       if (user && i < count) {
                offsets[1].id = 0;
                offsets[1].offset = gsf_output_tell (state->out);
                GSF_LE_SET_GUINT32 (buf, g_hash_table_size (state->dict));
                gsf_output_write (state->out, 4, buf);
                g_hash_table_foreach (state->dict,
                        (GHFunc) cb_write_dict, state);
-               i = 2;
-       } else
-               i = 1;
+               i++;
+       }
 
        /* 2) props */
        for (; ptr != NULL && i < count ; ptr = ptr->next, i++) {
@@ -1632,7 +1631,7 @@ msole_metadata_write_section (WritePropState *state, gboolean user)
                }
 
                msole_metadata_write_prop (state, name,
-                       gsf_doc_prop_get_val  (prop), FALSE);
+                       gsf_doc_prop_get_val (prop), FALSE);
                if (gsf_doc_prop_get_link (prop)) {
                        i++;
                        offsets[i].id     = offsets[i-1].id | 0x1000000;
diff --git a/gsf/gsf-structured-blob.c b/gsf/gsf-structured-blob.c
index caeadc7..07f4e1e 100644
--- a/gsf/gsf-structured-blob.c
+++ b/gsf/gsf-structured-blob.c
@@ -76,7 +76,7 @@ blob_dup (GsfInput *input, G_GNUC_UNUSED GError **err)
                gpointer child;
 
                dst->children = g_ptr_array_sized_new (src->children->len);
-               g_ptr_array_set_size  (dst->children, src->children->len);
+               g_ptr_array_set_size (dst->children, src->children->len);
                for (i = 0; i < src->children->len ; i++) {
                        child = g_ptr_array_index (src->children, i);
                        g_ptr_array_index (dst->children, i) = child
@@ -233,7 +233,7 @@ gsf_structured_blob_read (GsfInput *input)
        if (i > 0) {
 
                blob->children = g_ptr_array_sized_new (i);
-               g_ptr_array_set_size  (blob->children, i);
+               g_ptr_array_set_size (blob->children, i);
                while (i-- > 0) {
                        GsfInput *child = gsf_infile_child_by_index (GSF_INFILE (input), i);
                        GsfStructuredBlob *child_blob = NULL;
@@ -277,7 +277,7 @@ gsf_structured_blob_write (GsfStructuredBlob *blob, GsfOutfile *container)
 
        has_kids = (blob->children != NULL && blob->children->len > 0);
 
-       output = gsf_outfile_new_child  (GSF_OUTFILE (container),
+       output = gsf_outfile_new_child (GSF_OUTFILE (container),
                gsf_input_name (GSF_INPUT (blob)),
                has_kids);
        if (has_kids) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]