[gnumeric] odf: fix parse problems.



commit faab503dab381bfdad14bfb7c542e016c0bee435
Author: Morten Welinder <terra gnome org>
Date:   Sat Mar 29 15:59:42 2014 -0400

    odf: fix parse problems.
    
    Specifically UMRs on encountering an invalid reference.

 NEWS                                 |    1 +
 plugins/openoffice/ChangeLog         |    6 ++++++
 plugins/openoffice/openoffice-read.c |   28 ++++++++++++++++++++--------
 3 files changed, 27 insertions(+), 8 deletions(-)
---
diff --git a/NEWS b/NEWS
index 1ba9ae2..736fecc 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ Morten:
        * Fix problems with large, circular farms of VLOOKUP etc. [#723894]
        * Let goffice handle conditional number formats.
        * Attempt a workaround for Ubuntu scroll bars.
+       * Fix odf parse problems.
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.13
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 4829efa..6864e75 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-29  Morten Welinder  <terra gnome org>
+
+       * openoffice-read.c (oo_rangeref_parse): Handle parse failures (of
+       []) without reading undefined memory.
+       (oo_expr_rangeref_parse): Handle [] better.
+
 2014-03-28  Morten Welinder  <terra gnome org>
 
        * openoffice-read.c (odf_map): Fix condition !=.
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 578f8de..daaea0c 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -1424,6 +1424,7 @@ oo_rangeref_parse (GnmRangeRef *ref, char const *start, GnmParsePos const *pp,
                   GnmConventions const *convs)
 {
        char const *ptr;
+       char const *ptr2;
        char *external = NULL;
        char *external_sheet_1 = NULL;
        char *external_sheet_2 = NULL;
@@ -1431,15 +1432,25 @@ oo_rangeref_parse (GnmRangeRef *ref, char const *start, GnmParsePos const *pp,
 
        ptr = odf_parse_external (start, &external, convs);
 
-       ptr = oo_cellref_parse (&ref->a, ptr, pp,
-                               external == NULL ? NULL : &external_sheet_1);
-       if (*ptr == ':')
-               ptr = oo_cellref_parse (&ref->b, ptr+1, pp,
-                               external == NULL ? NULL : &external_sheet_2);
-       else
+       ptr2 = oo_cellref_parse (&ref->a, ptr, pp,
+                                external ? &external_sheet_1 : NULL);
+       if (ptr == ptr2)
+               return start;
+       ptr = ptr2;
+
+       if (*ptr == ':') {
+               ptr2 = oo_cellref_parse (&ref->b, ptr+1, pp,
+                                        external ? &external_sheet_2 : NULL);
+               if (ptr2 == ptr + 1)
+                       ref->b = ref->a;
+               else
+                       ptr = ptr2;
+       } else
                ref->b = ref->a;
+
        if (ref->b.sheet == invalid_sheet)
                ref->a.sheet = invalid_sheet;
+
        if (external != NULL) {
                Workbook *wb = pp->wb, *ext_wb;
                Workbook *ref_wb = wb ? wb : pp->sheet->workbook;
@@ -1477,7 +1488,7 @@ oo_expr_rangeref_parse (GnmRangeRef *ref, char const *start, GnmParsePos const *
                        GnmConventions const *convs)
 {
        char const *ptr;
-       if (*start == '[') {
+       if (start[0] == '[' && start[1] != ']') {
                if (strncmp (start, "[#REF!]", 7) == 0) {
                        ref->a.sheet = invalid_sheet;
                        return start + 7;
@@ -5333,6 +5344,7 @@ odf_cond_to_xl (GsfXMLIn *xin, GString *dst, const char *cond, int part, int par
        double val;
        const char *oper; /* xl-syntax */
        char *end;
+       const char *cond0 = cond;
 
        while (g_ascii_isspace (*cond))
                cond++;
@@ -5380,7 +5392,7 @@ odf_cond_to_xl (GsfXMLIn *xin, GString *dst, const char *cond, int part, int par
        return;
 
 bad:
-       oo_warning (xin, _("Corrupted file: invalid number format condition."));
+       oo_warning (xin, _("Corrupted file: invalid number format condition [%s]."), cond0);
 }
 
 


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