gnumeric r17261 - in trunk: . plugins/excel



Author: mortenw
Date: Tue Mar 31 13:40:05 2009
New Revision: 17261
URL: http://svn.gnome.org/viewvc/gnumeric?rev=17261&view=rev

Log:
2009-03-31  Morten Welinder  <terra gnome org>

	* ms-chart.c (ms_excel_chart_read): Leak less on errors.
	(BC_R(scatter)): Add sanity check for V8 case.  Fixes #577400.



Modified:
   trunk/NEWS
   trunk/plugins/excel/ChangeLog
   trunk/plugins/excel/ms-chart.c

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Tue Mar 31 13:40:05 2009
@@ -8,7 +8,7 @@
 	* Fix Applix loading crash.  [#577145]
 	* Fix Lotus loading crash.  [#577156]
 	* Fix XLS loading crashes.  [#577205] [#577208] [#577259] [#577260]
-	[#577348] [#577351] [#577399]
+	[#577348] [#577351] [#577399] [#577400]
 	* Add sorted sheet list to tab menu.
 	* Fix criticals during Lotus load.
 

Modified: trunk/plugins/excel/ms-chart.c
==============================================================================
--- trunk/plugins/excel/ms-chart.c	(original)
+++ trunk/plugins/excel/ms-chart.c	Tue Mar 31 13:40:05 2009
@@ -99,6 +99,7 @@
 typedef struct {
 	MSContainer	 container;
 
+	gboolean        error;
 	GArray		*stack;
 	MsBiffVersion	 ver;
 	guint32		 prev_opcode;
@@ -1750,7 +1751,11 @@
 	g_return_val_if_fail (s->plot == NULL, TRUE);
 
 	if (BC_R(ver)(s) >= MS_BIFF_V8) {
-		guint16 const flags = GSF_LE_GET_GUINT16 (q->data+4);
+		guint16 flags;
+
+		XL_CHECK_CONDITION_VAL (q->length >= 6, TRUE);
+
+		flags = GSF_LE_GET_GUINT16 (q->data + 4);
 
 		/* Has bubbles */
 		if (flags & 0x01) {
@@ -3504,6 +3509,7 @@
 	state.axis_cross_value = go_nan;
 	state.xaxis = NULL;
 	state.interpolation = GO_LINE_INTERPOLATION_LINEAR;
+	state.error = FALSE;
 
 	if (NULL != (state.sog = sog)) {
 		state.graph = sheet_object_graph_get_gog (sog);
@@ -3569,7 +3575,8 @@
 		case BIFF_EOF:
 			done = TRUE;
 			d (0, g_printerr ("}; /* CHART */\n"););
-			g_return_val_if_fail(state.stack->len == 0, TRUE);
+			if (state.stack->len > 0)
+				state.error = TRUE;
 			break;
 
 		case BIFF_PROTECT:
@@ -3642,7 +3649,7 @@
 	}
 
 	/* If there was no grid in the stream remove the automatic grid */
-	if (state.chart != NULL && !state.has_a_grid) {
+	if (!state.error && state.chart != NULL && !state.has_a_grid) {
 		GogGrid *grid = gog_chart_get_grid (state.chart);
 		if (grid != NULL) {
 			gog_object_clear_parent (GOG_OBJECT (grid));
@@ -3650,7 +3657,7 @@
 		}
 	}
 
-	for (i = state.series->len; i-- > 0 ; ) {
+	for (i = state.series->len; !state.error && i-- > 0 ; ) {
 		int j;
 		XLChartSeries *series = g_ptr_array_index (state.series, i);
 
@@ -3694,6 +3701,14 @@
 	g_array_free (state.stack, TRUE);
 	ms_container_finalize (&state.container);
 
+	if (state.error) {
+		if (state.graph) {
+			g_object_unref (state.graph);
+			state.graph = NULL;
+		}
+		state.chart = NULL;
+	}
+
 	if (state.chart) {
 		/* try to replace hidden axes by visible ones when possible */
 		GSList *l, *cur;
@@ -3737,7 +3752,7 @@
 		}
 	}
 
-	if (full_page != NULL) {
+	if (!state.error && full_page != NULL) {
 		static GnmRange const fixed_size = { { 1, 1 }, { 12, 32 } };
 		SheetObjectAnchor anchor;
 		sheet_object_anchor_init (&anchor, &fixed_size, NULL,
@@ -3752,8 +3767,7 @@
 	if (state.default_plot_style != NULL)
 		g_object_unref (state.default_plot_style);
 
-
-	return FALSE;
+	return state.error;
 }
 
 /* A wrapper which reads and checks the BOF record then calls ms_excel_chart_read */



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