gnumeric r17193 - in trunk: . plugins/lotus-123
- From: mortenw svn gnome org
- To: svn-commits-list gnome org
- Subject: gnumeric r17193 - in trunk: . plugins/lotus-123
- Date: Fri, 13 Mar 2009 13:02:19 +0000 (UTC)
Author: mortenw
Date: Fri Mar 13 13:02:19 2009
New Revision: 17193
URL: http://svn.gnome.org/viewvc/gnumeric?rev=17193&view=rev
Log:
2009-03-13 Morten Welinder <terra gnome org>
* boot.c (lotus_file_open): Initialize new state member
sheet_area_error.
* lotus.c (insert_value): Protect against NULL cell.
(lotus_read_new): Protect against NULL cell four times. Fixes
#575190.
(insert_value): Add new state argument. Plug leak.
(lotus_cell_fetch): New wrapper for sheet_cell_fetch so we can
produce dignified error messages.
* lotus-formula.c (lotus_parse_formula): If we get a NULL formula,
turn it into #VALUE!
Modified:
trunk/NEWS
trunk/plugins/lotus-123/ChangeLog
trunk/plugins/lotus-123/boot.c
trunk/plugins/lotus-123/lotus-formula.c
trunk/plugins/lotus-123/lotus.c
trunk/plugins/lotus-123/lotus.h
Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS (original)
+++ trunk/NEWS Fri Mar 13 13:02:19 2009
@@ -22,6 +22,7 @@
* Fix sheet-ordering by dragging. [#574763]
* Fix potential crash for cell comment dialog with multiple views.
[Part of #364291]
+ * Fix lotus importer crash. [#575190]
Sum1:
* Implement OOO probing. [#574381]
Modified: trunk/plugins/lotus-123/boot.c
==============================================================================
--- trunk/plugins/lotus-123/boot.c (original)
+++ trunk/plugins/lotus-123/boot.c Fri Mar 13 13:02:19 2009
@@ -79,6 +79,7 @@
state.wbv = wb_view;
state.wb = wb_view_get_workbook (wb_view);
state.sheet = NULL;
+ state.sheet_area_error = FALSE;
if (!lotus_read (&state))
gnumeric_io_error_string (io_context,
Modified: trunk/plugins/lotus-123/lotus-formula.c
==============================================================================
--- trunk/plugins/lotus-123/lotus-formula.c (original)
+++ trunk/plugins/lotus-123/lotus-formula.c Fri Mar 13 13:02:19 2009
@@ -777,6 +777,9 @@
? lotus_parse_formula_new (state, pos, data, len)
: lotus_parse_formula_old (state, pos, data, len);
+ if (!result)
+ result = gnm_expr_top_new_constant (value_new_error_VALUE (NULL));
+
#if FORMULA_DEBUG > 0
{
char *txt = gnm_expr_top_as_string (result, pos, gnm_conventions_default);
Modified: trunk/plugins/lotus-123/lotus.c
==============================================================================
--- trunk/plugins/lotus-123/lotus.c (original)
+++ trunk/plugins/lotus-123/lotus.c Fri Mar 13 13:02:19 2009
@@ -1454,22 +1454,44 @@
/* ------------------------------------------------------------------------- */
static GnmCell *
-insert_value (Sheet *sheet, guint32 col, guint32 row, GnmValue *val)
+lotus_cell_fetch (LotusState *state, Sheet *sheet, guint32 col, guint32 row)
+{
+ if (col >= gnm_sheet_get_max_cols (sheet) ||
+ row >= gnm_sheet_get_max_rows (sheet)) {
+ if (!state->sheet_area_error) {
+ state->sheet_area_error = TRUE;
+ g_warning ("File is most likely corrupted.\n"
+ "(It claims to contain a cell outside the range Gnumeric can handle.)");
+ }
+
+ return NULL;
+ }
+
+ return sheet_cell_fetch (sheet, col, row);
+}
+
+
+
+static GnmCell *
+insert_value (LotusState *state, Sheet *sheet, guint32 col, guint32 row, GnmValue *val)
{
GnmCell *cell;
g_return_val_if_fail (val != NULL, NULL);
g_return_val_if_fail (sheet != NULL, NULL);
- cell = sheet_cell_fetch (sheet, col, row);
-
- gnm_cell_set_value (cell, val);
+ cell = lotus_cell_fetch (state, sheet, col, row);
+ if (cell) {
+ gnm_cell_set_value (cell, val);
#if LOTUS_DEBUG > 0
- printf ("Inserting value at %s:\n",
- cell_name (cell));
- value_dump (val);
+ printf ("Inserting value at %s:\n",
+ cell_name (cell));
+ value_dump (val);
#endif
+ } else
+ value_release (val);
+
return cell;
}
@@ -1518,7 +1540,7 @@
int i = GSF_LE_GET_GUINT16 (r->data + 1);
int j = GSF_LE_GET_GUINT16 (r->data + 3);
- cell = insert_value (state->sheet, i, j, v);
+ cell = insert_value (state, state->sheet, i, j, v);
if (cell)
cell_set_format_from_lotus_format (cell, fmt);
break;
@@ -1529,7 +1551,7 @@
int i = GSF_LE_GET_GUINT16 (r->data + 1);
int j = GSF_LE_GET_GUINT16 (r->data + 3);
- cell = insert_value (state->sheet, i, j, v);
+ cell = insert_value (state, state->sheet, i, j, v);
if (cell)
cell_set_format_from_lotus_format (cell, fmt);
break;
@@ -1541,7 +1563,7 @@
guint8 fmt = GSF_LE_GET_GUINT8 (r->data);
int i = GSF_LE_GET_GUINT16 (r->data + 1);
int j = GSF_LE_GET_GUINT16 (r->data + 3);
- cell = insert_value (state->sheet, i, j, v);
+ cell = insert_value (state, state->sheet, i, j, v);
if (cell)
cell_set_format_from_lotus_format (cell, fmt);
break;
@@ -1580,11 +1602,13 @@
v = value_new_error_VALUE (NULL);
} else
v = lotus_value (gsf_le_get_double (r->data + 5));
- cell = sheet_cell_fetch (state->sheet, col, row);
- gnm_cell_set_expr_and_value (cell, texpr, v, TRUE);
-
+ cell = lotus_cell_fetch (state, state->sheet, col, row);
+ if (cell) {
+ gnm_cell_set_expr_and_value (cell, texpr, v, TRUE);
+ cell_set_format_from_lotus_format (cell, fmt);
+ } else
+ value_release (v);
gnm_expr_top_unref (texpr);
- cell_set_format_from_lotus_format (cell, fmt);
break;
}
@@ -1878,7 +1902,7 @@
Sheet *sheet = lotus_get_sheet (state->wb, r->data[2]);
int col = r->data[3];
GnmValue *v = value_new_error_VALUE (NULL);
- (void)insert_value (sheet, col, row, v);
+ (void)insert_value (state, sheet, col, row, v);
break;
}
@@ -1887,7 +1911,7 @@
Sheet *sheet = lotus_get_sheet (state->wb, r->data[2]);
int col = r->data[3];
GnmValue *v = value_new_error_NA (NULL);
- (void)insert_value (sheet, col, row, v);
+ (void)insert_value (state, sheet, col, row, v);
break;
}
@@ -1898,7 +1922,7 @@
int col = r->data[3];
/* gchar format_prefix = *(r->data + ofs + 4);*/
GnmValue *v = lotus_new_string (r->data + 5, state->lmbcs_group);
- (void)insert_value (sheet, col, row, v);
+ (void)insert_value (state, sheet, col, row, v);
break;
}
@@ -1907,7 +1931,7 @@
Sheet *sheet = lotus_get_sheet (state->wb, r->data[2]);
int col = r->data[3];
GnmValue *v = lotus_lnumber (r, 4);
- (void)insert_value (sheet, col, row, v);
+ (void)insert_value (state, sheet, col, row, v);
break;
}
@@ -1916,7 +1940,7 @@
Sheet *sheet = lotus_get_sheet (state->wb, r->data[2]);
int col = r->data[3];
GnmValue *v = lotus_smallnum (GSF_LE_GET_GINT16 (r->data + 4));
- (void)insert_value (sheet, col, row, v);
+ (void)insert_value (state, sheet, col, row, v);
break;
}
@@ -2057,7 +2081,7 @@
Sheet *sheet = lotus_get_sheet (state->wb, r->data[2]);
int col = r->data[3];
GnmValue *val = lotus_unpack_number (GSF_LE_GET_GUINT32 (r->data + 4));
- (void)insert_value (sheet, col, row, val);
+ (void)insert_value (state, sheet, col, row, val);
break;
}
@@ -2094,8 +2118,11 @@
texpr = lotus_parse_formula (state, &pp,
r->data + 12,
r->len - 12);
- cell = sheet_cell_fetch (sheet, col, row);
- gnm_cell_set_expr_and_value (cell, texpr, curval, TRUE);
+ cell = lotus_cell_fetch (state, sheet, col, row);
+ if (cell)
+ gnm_cell_set_expr_and_value (cell, texpr, curval, TRUE);
+ else
+ value_release (curval);
gnm_expr_top_unref (texpr);
break;
@@ -2117,8 +2144,11 @@
texpr = lotus_parse_formula (state, &pp,
r->data + 14,
r->len - 14);
- cell = sheet_cell_fetch (sheet, col, row);
- gnm_cell_set_expr_and_value (cell, texpr, curval, TRUE);
+ cell = lotus_cell_fetch (state, sheet, col, row);
+ if (cell)
+ gnm_cell_set_expr_and_value (cell, texpr, curval, TRUE);
+ else
+ value_release (curval);
gnm_expr_top_unref (texpr);
break;
Modified: trunk/plugins/lotus-123/lotus.h
==============================================================================
--- trunk/plugins/lotus-123/lotus.h (original)
+++ trunk/plugins/lotus-123/lotus.h Fri Mar 13 13:02:19 2009
@@ -24,6 +24,7 @@
guint8 lmbcs_group;
GHashTable *style_pool;
+ gboolean sheet_area_error;
} LotusState;
Sheet *lotus_get_sheet (Workbook *wb, int i);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]