Fixed crash reading ODS spreadsheets and added a test case 20130305030502/pspp 20130306030504/pspp 20130307030505/pspp
authorJohn Darrington <john@darrington.wattle.id.au>
Tue, 5 Mar 2013 08:15:35 +0000 (09:15 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Tue, 5 Mar 2013 08:15:35 +0000 (09:15 +0100)
src/data/ods-reader.c
tests/language/data-io/get-data-spreadsheet.at

index 97f9e33441d277de0d3d55ace4fd2540519d35ed..5f5c0eed9374573c04733463550d5a30d10d8822 100644 (file)
@@ -652,15 +652,6 @@ ods_make_reader (struct spreadsheet *spreadsheet,
   r->row = r->col = 0;
 
 
-#if 0
-  printf ("%s:%d %d,%d %d,%d\n", __FILE__, __LINE__, 
-         r->start_col,
-         r->start_row,
-         r->stop_col,
-         r->stop_row);
-#endif
-
-
   /* Advance to the start of the cells for the target sheet */
   while ( ! reading_target_sheet (r)  
          || r->state != STATE_ROW || r->row <= r->start_row )
@@ -756,14 +747,6 @@ ods_make_reader (struct spreadsheet *spreadsheet,
       if ( r->state == STATE_CELL_CONTENT &&
           XML_READER_TYPE_TEXT  == r->node_type)
        {
-#if 0
-         printf ("%s:%d Idx %d n_var_specs %d\n", __FILE__, __LINE__,
-                 idx, n_var_specs);
-
-         printf ("%s:%d Idx %d r_col %d\n", __FILE__, __LINE__,
-                 idx, r->col);
-#endif
-
          if (idx >= n_var_specs)
            {
              var_spec = xrealloc (var_spec, sizeof (*var_spec) * (idx + 1));
@@ -953,6 +936,8 @@ ods_file_casereader_read (struct casereader *reader UNUSED, void *r_)
                continue;
              if (r->stop_col != -1 && idx > r->stop_col - r->start_col )
                break;
+             if (idx >= dict_get_var_cnt (r->dict))
+               break;
 
               var = dict_get_var (r->dict, idx);
              convert_xml_to_value (c, var, xmv);
index 147458f378908ba78404a3a4c5394e77376f8c96..28b9686c863b4b64efba5bc8b3bf3967633f8a8a 100644 (file)
@@ -147,6 +147,22 @@ vone,vtwo,vthree,v4
 ])
 AT_CLEANUP
 
+dnl This syntax doesn't do anything particularly useful.
+dnl It has been seen to cause a few crashes, so we check here that it
+dnl doesn't do anthing bad.
+AT_SETUP([GET DATA /TYPE=$1 with no options])
+SPREADSHEET_TEST_PREP($1)
+AT_DATA([get-data.sps], [dnl
+* This sheet is empty
+GET DATA /TYPE=$1 /FILE='testsheet'.
+DISPLAY DICTIONARY.
+LIST.
+])
+AT_CHECK([pspp -o pspp.csv get-data.sps], [0], [ignore])
+AT_CLEANUP
+
+
+
 AT_SETUP([GET DATA /TYPE=$1 with empty sheet])
 SPREADSHEET_TEST_PREP($1)
 AT_DATA([get-data.sps], [dnl