~ubuntu-branches/ubuntu/breezy/koffice/breezy-security

« back to all changes in this revision

Viewing changes to filters/kspread/excel/sidewinder/sheet.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-10-11 14:49:50 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051011144950-lwpngbifzp8nk0ds
Tags: 1:1.4.1-0ubuntu7
* SECURITY UPDATE: fix heap based buffer overflow in the RTF importer of KWord
* Opening specially crafted RTF files in KWord can cause
  execution of abitrary code.
* Add kubuntu_01_rtfimport_heap_overflow.diff
* References:
  CAN-2005-2971
  CESA-2005-005
  http://www.koffice.org/security/advisory-20051011-1.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Sidewinder - Portable library for spreadsheet
2
 
   Copyright (C) 2003 Ariya Hidayat <ariya@kde.org>
3
 
 
4
 
   This library is free software; you can redistribute it and/or
5
 
   modify it under the terms of the GNU Library General Public
6
 
   License as published by the Free Software Foundation; either
7
 
   version 2 of the License, or (at your option) any later version.
8
 
   
9
 
   This library is distributed in the hope that it will be useful,
10
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 
   Library General Public License for more details.
13
 
 
14
 
   You should have received a copy of the GNU Library General Public License
15
 
   along with this library; see the file COPYING.LIB.  If not, write to
16
 
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
 
   Boston, MA 02111-1307, US
18
 
*/
19
 
 
20
 
#include "cell.h"
21
 
#include "sheet.h"
22
 
#include "workbook.h"
23
 
#include "ustring.h"
24
 
 
25
 
#include <iostream>
26
 
#include <map>
27
 
 
28
 
namespace Sidewinder
29
 
{
30
 
 
31
 
class Sheet::Private
32
 
{
33
 
public:
34
 
  Workbook* workbook;
35
 
  UString name;
36
 
    
37
 
  // hash to store cell, FIXME replace with quad-tree
38
 
  std::map<unsigned,Cell*> cells;
39
 
  unsigned maxRow;
40
 
  unsigned maxColumn;
41
 
  std::map<unsigned,Column*> columns;
42
 
  std::map<unsigned,Row*> rows;
43
 
  
44
 
  bool visible;
45
 
  bool protect;
46
 
 
47
 
  UString leftHeader;
48
 
  UString centerHeader;
49
 
  UString rightHeader;
50
 
  UString leftFooter;
51
 
  UString centerFooter;
52
 
  UString rightFooter;
53
 
 
54
 
  double leftMargin;
55
 
  double rightMargin;
56
 
  double topMargin;
57
 
  double bottomMargin;
58
 
};
59
 
 
60
 
};
61
 
 
62
 
using namespace Sidewinder;
63
 
 
64
 
Sheet::Sheet( Workbook* wb )
65
 
{
66
 
  d = new Sheet::Private();
67
 
  d->workbook = wb;
68
 
  d->name = "Sheet"; // FIXME better name ?
69
 
  d->maxRow = 0;
70
 
  d->maxColumn = 0;
71
 
  d->visible      = true;
72
 
  d->protect      = false;
73
 
  d->leftMargin   = 54;  // 0.75 inch
74
 
  d->rightMargin  = 54;  // 0.75 inch
75
 
  d->topMargin    = 72;  // 1 inch
76
 
  d->bottomMargin = 72;  // 1 inch
77
 
}
78
 
 
79
 
Sheet::~Sheet()
80
 
{
81
 
  // TODO delete all cells, columns, rows
82
 
  delete d;
83
 
}
84
 
 
85
 
Workbook* Sheet::workbook()
86
 
{
87
 
  return d->workbook;
88
 
}
89
 
 
90
 
UString Sheet::name() const
91
 
{
92
 
  return d->name;
93
 
}
94
 
 
95
 
void Sheet::setName( const UString& name )
96
 
{
97
 
  d->name = name;
98
 
}
99
 
 
100
 
Cell* Sheet::cell( unsigned column, unsigned row, bool autoCreate )
101
 
{
102
 
  unsigned hashed = (row+1)*1024 + column + 1;
103
 
  Cell* c = d->cells[ hashed ];
104
 
  
105
 
  // create cell if necessary
106
 
  if( !c && autoCreate )
107
 
  {
108
 
    c = new Cell( this, column, row );
109
 
    d->cells[ hashed ] = c;
110
 
    
111
 
    if( row > d->maxRow ) d->maxRow = row;
112
 
    if( column > d->maxColumn ) d->maxColumn = column;
113
 
  }
114
 
  
115
 
  return c;
116
 
}
117
 
 
118
 
Column* Sheet::column( unsigned index, bool autoCreate )
119
 
{
120
 
  Column* c = d->columns[ index ];
121
 
  
122
 
  // create column if necessary
123
 
  if( !c && autoCreate )
124
 
  {
125
 
    c = new Column( this, index );
126
 
    d->columns[ index ] = c;
127
 
    if( index > d->maxColumn ) d->maxColumn = index;
128
 
  }
129
 
  
130
 
  return c;
131
 
}
132
 
 
133
 
Row* Sheet::row( unsigned index, bool autoCreate )
134
 
{
135
 
  Row* r = d->rows[ index ];
136
 
  
137
 
  // create row if necessary
138
 
  if( !r && autoCreate )
139
 
  {
140
 
    r = new Row( this, index );
141
 
    d->rows[ index ] = r;
142
 
    if( index > d->maxRow ) d->maxRow = index;
143
 
  }
144
 
  
145
 
  return r;
146
 
}
147
 
 
148
 
unsigned Sheet::maxRow() const
149
 
{
150
 
  return d->maxRow;
151
 
}
152
 
 
153
 
unsigned Sheet::maxColumn() const
154
 
{
155
 
  return d->maxColumn;
156
 
}
157
 
 
158
 
bool Sheet::visible() const
159
 
{
160
 
  return d->visible;
161
 
}
162
 
 
163
 
void Sheet::setVisible( bool v )
164
 
{
165
 
  d->visible = v;
166
 
}
167
 
 
168
 
bool Sheet::protect() const
169
 
{
170
 
  return d->protect;
171
 
}
172
 
 
173
 
void Sheet::setProtect( bool p )
174
 
{
175
 
  d->protect = p;
176
 
}
177
 
 
178
 
UString Sheet::leftHeader() const
179
 
{
180
 
  return d->leftHeader;
181
 
}
182
 
 
183
 
void Sheet::setLeftHeader( const UString& h )
184
 
{
185
 
  d->leftHeader = h;
186
 
}
187
 
 
188
 
UString Sheet::centerHeader() const
189
 
{
190
 
  return d->centerHeader;
191
 
}
192
 
 
193
 
void Sheet::setCenterHeader( const UString& h )
194
 
{
195
 
  d->centerHeader = h;
196
 
}
197
 
 
198
 
UString Sheet::rightHeader() const
199
 
{
200
 
  return d->rightHeader;
201
 
}
202
 
 
203
 
void Sheet::setRightHeader( const UString& h )
204
 
{
205
 
  d->rightHeader = h;
206
 
}
207
 
 
208
 
UString Sheet::leftFooter() const
209
 
{
210
 
  return d->leftFooter;
211
 
}
212
 
 
213
 
void Sheet::setLeftFooter( const UString& h )
214
 
{
215
 
  d->leftFooter = h;
216
 
}
217
 
 
218
 
UString Sheet::centerFooter() const
219
 
{
220
 
  return d->centerFooter;
221
 
}
222
 
 
223
 
void Sheet::setCenterFooter( const UString& h )
224
 
{
225
 
  d->centerFooter = h;
226
 
}
227
 
 
228
 
UString Sheet::rightFooter() const
229
 
{
230
 
  return d->rightFooter;
231
 
}
232
 
 
233
 
void Sheet::setRightFooter( const UString& h )
234
 
{
235
 
  d->rightFooter = h;
236
 
}
237
 
 
238
 
double Sheet::leftMargin() const
239
 
{
240
 
  return d->leftMargin;
241
 
}
242
 
 
243
 
void Sheet::setLeftMargin( double m )
244
 
{
245
 
  d->leftMargin = m;
246
 
}
247
 
 
248
 
double Sheet::rightMargin() const
249
 
{
250
 
  return d->rightMargin;
251
 
}
252
 
 
253
 
void Sheet::setRightMargin( double m ) 
254
 
{
255
 
  d->rightMargin = m;
256
 
}
257
 
 
258
 
double Sheet::topMargin() const
259
 
{
260
 
  return d->topMargin;
261
 
}
262
 
 
263
 
void Sheet::setTopMargin( double m ) 
264
 
{
265
 
  d->topMargin = m;
266
 
}
267
 
 
268
 
double Sheet::bottomMargin() const
269
 
{
270
 
  return d->bottomMargin;
271
 
}
272
 
 
273
 
void Sheet::setBottomMargin( double m ) 
274
 
{
275
 
  d->bottomMargin = m;
276
 
}
277
 
 
278
 
class Column::Private
279
 
{
280
 
public:
281
 
  Sheet* sheet;
282
 
  unsigned index;
283
 
  double width;
284
 
  Format format;
285
 
  bool visible;
286
 
};
287
 
 
288
 
Column::Column( Sheet* sheet, unsigned index )
289
 
{
290
 
  d = new Column::Private;
291
 
  d->sheet   = sheet;
292
 
  d->index   = index;
293
 
  d->width   = 10;
294
 
  d->visible = true;
295
 
}
296
 
 
297
 
Column::~Column()
298
 
{
299
 
  delete d;
300
 
}
301
 
 
302
 
Sheet* Column::sheet() const
303
 
{
304
 
  return d->sheet;
305
 
}
306
 
 
307
 
unsigned Column::index() const
308
 
{
309
 
  return d->index;
310
 
}
311
 
 
312
 
double Column::width() const
313
 
{
314
 
  return d->width;
315
 
}
316
 
 
317
 
void Column::setWidth( double w )
318
 
{
319
 
  d->width = w;
320
 
}
321
 
 
322
 
const Format& Column::format() const
323
 
{
324
 
  return d->format;
325
 
}
326
 
 
327
 
void Column::setFormat( const Format& f )
328
 
{
329
 
  d->format = f;
330
 
}
331
 
 
332
 
bool Column::visible() const
333
 
{
334
 
  return d->visible;
335
 
}
336
 
 
337
 
void Column::setVisible( bool b )
338
 
{
339
 
  d->visible = b;
340
 
}
341
 
 
342
 
class Row::Private
343
 
{
344
 
public:
345
 
  Sheet* sheet;
346
 
  unsigned index;
347
 
  double height;
348
 
  Format format;
349
 
  bool visible;
350
 
};
351
 
 
352
 
Row::Row( Sheet* sheet, unsigned index )
353
 
{
354
 
  d = new Row::Private;
355
 
  d->sheet   = sheet;
356
 
  d->index   = index;
357
 
  d->height  = 10;
358
 
  d->visible = true;
359
 
}
360
 
 
361
 
Row::~Row()
362
 
{
363
 
  delete d;
364
 
}
365
 
 
366
 
Sheet* Row::sheet() const
367
 
{
368
 
  return d->sheet;
369
 
}
370
 
 
371
 
unsigned Row::index() const
372
 
{
373
 
  return d->index;
374
 
}
375
 
 
376
 
double Row::height() const
377
 
{
378
 
  return d->height;
379
 
}
380
 
 
381
 
void Row::setHeight( double w )
382
 
{
383
 
  d->height = w;
384
 
}
385
 
 
386
 
const Format& Row::format() const
387
 
{
388
 
  return d->format;
389
 
}
390
 
 
391
 
void Row::setFormat( const Format& f )
392
 
{
393
 
  d->format = f;
394
 
}
395
 
 
396
 
bool Row::visible() const
397
 
{
398
 
  return d->visible;
399
 
}
400
 
 
401
 
void Row::setVisible( bool b )
402
 
{
403
 
  d->visible = b;
404
 
}
 
1
/* Swinder - Portable library for spreadsheet
 
2
   Copyright (C) 2003 Ariya Hidayat <ariya@kde.org>
 
3
 
 
4
   This library is free software; you can redistribute it and/or
 
5
   modify it under the terms of the GNU Library General Public
 
6
   License as published by the Free Software Foundation; either
 
7
   version 2 of the License, or (at your option) any later version.
 
8
   
 
9
   This library is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
   Library General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU Library General Public License
 
15
   along with this library; see the file COPYING.LIB.  If not, write to
 
16
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
   Boston, MA 02111-1307, US
 
18
*/
 
19
 
 
20
#include "cell.h"
 
21
#include "sheet.h"
 
22
#include "workbook.h"
 
23
#include "ustring.h"
 
24
 
 
25
#include <iostream>
 
26
#include <map>
 
27
 
 
28
namespace Swinder
 
29
{
 
30
 
 
31
class Sheet::Private
 
32
{
 
33
public:
 
34
  Workbook* workbook;
 
35
  UString name;
 
36
    
 
37
  // hash to store cell, FIXME replace with quad-tree
 
38
  std::map<unsigned,Cell*> cells;
 
39
  unsigned maxRow;
 
40
  unsigned maxColumn;
 
41
  std::map<unsigned,Column*> columns;
 
42
  std::map<unsigned,Row*> rows;
 
43
  
 
44
  bool visible;
 
45
  bool protect;
 
46
 
 
47
  UString leftHeader;
 
48
  UString centerHeader;
 
49
  UString rightHeader;
 
50
  UString leftFooter;
 
51
  UString centerFooter;
 
52
  UString rightFooter;
 
53
 
 
54
  double leftMargin;
 
55
  double rightMargin;
 
56
  double topMargin;
 
57
  double bottomMargin;
 
58
};
 
59
 
 
60
}
 
61
 
 
62
using namespace Swinder;
 
63
 
 
64
Sheet::Sheet( Workbook* wb )
 
65
{
 
66
  d = new Sheet::Private();
 
67
  d->workbook = wb;
 
68
  d->name = "Sheet"; // FIXME better name ?
 
69
  d->maxRow = 0;
 
70
  d->maxColumn = 0;
 
71
  d->visible      = true;
 
72
  d->protect      = false;
 
73
  d->leftMargin   = 54;  // 0.75 inch
 
74
  d->rightMargin  = 54;  // 0.75 inch
 
75
  d->topMargin    = 72;  // 1 inch
 
76
  d->bottomMargin = 72;  // 1 inch
 
77
}
 
78
 
 
79
Sheet::~Sheet()
 
80
{
 
81
  clear();
 
82
  delete d;
 
83
}
 
84
 
 
85
Workbook* Sheet::workbook()
 
86
{
 
87
  return d->workbook;
 
88
}
 
89
 
 
90
void Sheet::clear()
 
91
{
 
92
  // delete all cells
 
93
  std::map<unsigned,Cell*>::iterator cell_it;
 
94
  for( cell_it = d->cells.begin(); cell_it != d->cells.end(); ++cell_it )
 
95
    delete cell_it->second;
 
96
  
 
97
  // delete all columns
 
98
  std::map<unsigned,Column*>::iterator col_it;
 
99
  for( col_it = d->columns.begin(); col_it != d->columns.end(); ++col_it )
 
100
    delete col_it->second;
 
101
  
 
102
  // delete all rows
 
103
  std::map<unsigned,Row*>::iterator row_it;
 
104
  for( row_it = d->rows.begin(); row_it != d->rows.end(); ++row_it )
 
105
    delete row_it->second;
 
106
}
 
107
 
 
108
UString Sheet::name() const
 
109
{
 
110
  return d->name;
 
111
}
 
112
 
 
113
void Sheet::setName( const UString& name )
 
114
{
 
115
  d->name = name;
 
116
}
 
117
 
 
118
Cell* Sheet::cell( unsigned column, unsigned row, bool autoCreate )
 
119
{
 
120
  unsigned hashed = (row+1)*1024 + column + 1;
 
121
  Cell* c = d->cells[ hashed ];
 
122
  
 
123
  // create cell if necessary
 
124
  if( !c && autoCreate )
 
125
  {
 
126
    c = new Cell( this, column, row );
 
127
    d->cells[ hashed ] = c;
 
128
    
 
129
    if( row > d->maxRow ) d->maxRow = row;
 
130
    if( column > d->maxColumn ) d->maxColumn = column;
 
131
  }
 
132
  
 
133
  return c;
 
134
}
 
135
 
 
136
Column* Sheet::column( unsigned index, bool autoCreate )
 
137
{
 
138
  Column* c = d->columns[ index ];
 
139
  
 
140
  // create column if necessary
 
141
  if( !c && autoCreate )
 
142
  {
 
143
    c = new Column( this, index );
 
144
    d->columns[ index ] = c;
 
145
    if( index > d->maxColumn ) d->maxColumn = index;
 
146
  }
 
147
  
 
148
  return c;
 
149
}
 
150
 
 
151
Row* Sheet::row( unsigned index, bool autoCreate )
 
152
{
 
153
  Row* r = d->rows[ index ];
 
154
  
 
155
  // create row if necessary
 
156
  if( !r && autoCreate )
 
157
  {
 
158
    r = new Row( this, index );
 
159
    d->rows[ index ] = r;
 
160
    if( index > d->maxRow ) d->maxRow = index;
 
161
  }
 
162
  
 
163
  return r;
 
164
}
 
165
 
 
166
unsigned Sheet::maxRow() const
 
167
{
 
168
  return d->maxRow;
 
169
}
 
170
 
 
171
unsigned Sheet::maxColumn() const
 
172
{
 
173
  return d->maxColumn;
 
174
}
 
175
 
 
176
bool Sheet::visible() const
 
177
{
 
178
  return d->visible;
 
179
}
 
180
 
 
181
void Sheet::setVisible( bool v )
 
182
{
 
183
  d->visible = v;
 
184
}
 
185
 
 
186
bool Sheet::protect() const
 
187
{
 
188
  return d->protect;
 
189
}
 
190
 
 
191
void Sheet::setProtect( bool p )
 
192
{
 
193
  d->protect = p;
 
194
}
 
195
 
 
196
UString Sheet::leftHeader() const
 
197
{
 
198
  return d->leftHeader;
 
199
}
 
200
 
 
201
void Sheet::setLeftHeader( const UString& h )
 
202
{
 
203
  d->leftHeader = h;
 
204
}
 
205
 
 
206
UString Sheet::centerHeader() const
 
207
{
 
208
  return d->centerHeader;
 
209
}
 
210
 
 
211
void Sheet::setCenterHeader( const UString& h )
 
212
{
 
213
  d->centerHeader = h;
 
214
}
 
215
 
 
216
UString Sheet::rightHeader() const
 
217
{
 
218
  return d->rightHeader;
 
219
}
 
220
 
 
221
void Sheet::setRightHeader( const UString& h )
 
222
{
 
223
  d->rightHeader = h;
 
224
}
 
225
 
 
226
UString Sheet::leftFooter() const
 
227
{
 
228
  return d->leftFooter;
 
229
}
 
230
 
 
231
void Sheet::setLeftFooter( const UString& h )
 
232
{
 
233
  d->leftFooter = h;
 
234
}
 
235
 
 
236
UString Sheet::centerFooter() const
 
237
{
 
238
  return d->centerFooter;
 
239
}
 
240
 
 
241
void Sheet::setCenterFooter( const UString& h )
 
242
{
 
243
  d->centerFooter = h;
 
244
}
 
245
 
 
246
UString Sheet::rightFooter() const
 
247
{
 
248
  return d->rightFooter;
 
249
}
 
250
 
 
251
void Sheet::setRightFooter( const UString& h )
 
252
{
 
253
  d->rightFooter = h;
 
254
}
 
255
 
 
256
double Sheet::leftMargin() const
 
257
{
 
258
  return d->leftMargin;
 
259
}
 
260
 
 
261
void Sheet::setLeftMargin( double m )
 
262
{
 
263
  d->leftMargin = m;
 
264
}
 
265
 
 
266
double Sheet::rightMargin() const
 
267
{
 
268
  return d->rightMargin;
 
269
}
 
270
 
 
271
void Sheet::setRightMargin( double m ) 
 
272
{
 
273
  d->rightMargin = m;
 
274
}
 
275
 
 
276
double Sheet::topMargin() const
 
277
{
 
278
  return d->topMargin;
 
279
}
 
280
 
 
281
void Sheet::setTopMargin( double m ) 
 
282
{
 
283
  d->topMargin = m;
 
284
}
 
285
 
 
286
double Sheet::bottomMargin() const
 
287
{
 
288
  return d->bottomMargin;
 
289
}
 
290
 
 
291
void Sheet::setBottomMargin( double m ) 
 
292
{
 
293
  d->bottomMargin = m;
 
294
}
 
295
 
 
296
class Column::Private
 
297
{
 
298
public:
 
299
  Sheet* sheet;
 
300
  unsigned index;
 
301
  double width;
 
302
  Format format;
 
303
  bool visible;
 
304
};
 
305
 
 
306
Column::Column( Sheet* sheet, unsigned index )
 
307
{
 
308
  d = new Column::Private;
 
309
  d->sheet   = sheet;
 
310
  d->index   = index;
 
311
  d->width   = 10;
 
312
  d->visible = true;
 
313
}
 
314
 
 
315
Column::~Column()
 
316
{
 
317
  delete d;
 
318
}
 
319
 
 
320
Sheet* Column::sheet() const
 
321
{
 
322
  return d->sheet;
 
323
}
 
324
 
 
325
unsigned Column::index() const
 
326
{
 
327
  return d->index;
 
328
}
 
329
 
 
330
double Column::width() const
 
331
{
 
332
  return d->width;
 
333
}
 
334
 
 
335
void Column::setWidth( double w )
 
336
{
 
337
  d->width = w;
 
338
}
 
339
 
 
340
const Format& Column::format() const
 
341
{
 
342
  return d->format;
 
343
}
 
344
 
 
345
void Column::setFormat( const Format& f )
 
346
{
 
347
  d->format = f;
 
348
}
 
349
 
 
350
bool Column::visible() const
 
351
{
 
352
  return d->visible;
 
353
}
 
354
 
 
355
void Column::setVisible( bool b )
 
356
{
 
357
  d->visible = b;
 
358
}
 
359
 
 
360
class Row::Private
 
361
{
 
362
public:
 
363
  Sheet* sheet;
 
364
  unsigned index;
 
365
  double height;
 
366
  Format format;
 
367
  bool visible;
 
368
};
 
369
 
 
370
Row::Row( Sheet* sheet, unsigned index )
 
371
{
 
372
  d = new Row::Private;
 
373
  d->sheet   = sheet;
 
374
  d->index   = index;
 
375
  d->height  = 10;
 
376
  d->visible = true;
 
377
}
 
378
 
 
379
Row::~Row()
 
380
{
 
381
  delete d;
 
382
}
 
383
 
 
384
Sheet* Row::sheet() const
 
385
{
 
386
  return d->sheet;
 
387
}
 
388
 
 
389
unsigned Row::index() const
 
390
{
 
391
  return d->index;
 
392
}
 
393
 
 
394
double Row::height() const
 
395
{
 
396
  return d->height;
 
397
}
 
398
 
 
399
void Row::setHeight( double w )
 
400
{
 
401
  d->height = w;
 
402
}
 
403
 
 
404
const Format& Row::format() const
 
405
{
 
406
  return d->format;
 
407
}
 
408
 
 
409
void Row::setFormat( const Format& f )
 
410
{
 
411
  d->format = f;
 
412
}
 
413
 
 
414
bool Row::visible() const
 
415
{
 
416
  return d->visible;
 
417
}
 
418
 
 
419
void Row::setVisible( bool b )
 
420
{
 
421
  d->visible = b;
 
422
}