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

« back to all changes in this revision

Viewing changes to kspread/kspread_selection.cc

  • 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:
20
20
#include "kspread_selection.h"
21
21
#include "kspread_canvas.h"
22
22
#include "kspread_cell.h"
 
23
#include "kspread_doc.h"
23
24
#include "kspread_global.h"
24
25
#include "kspread_sheet.h"
25
26
#include "kspread_view.h"
34
35
  m_chooseAnchor = QPoint(0,0);
35
36
  m_chooseCursor = QPoint(0,0);
36
37
 
37
 
  m_chooseTable = NULL;
 
38
  m_chooseSheet = NULL;
38
39
  m_pView = view;
39
40
}
40
41
 
69
70
  return m_marker;
70
71
}
71
72
 
72
 
QRect KSpreadSelection::selection() const
 
73
QRect KSpreadSelection::selection(bool extend) const
73
74
{
74
75
  int left, top, right, bottom;
75
76
  left = QMIN(m_anchor.x(), m_marker.x());
78
79
  bottom = QMAX(m_anchor.y(), m_marker.y());
79
80
  QRect selection(QPoint(left, top), QPoint(right, bottom));
80
81
 
81
 
  return extendToMergedAreas(selection);
 
82
  if (extend)
 
83
      return extendToMergedAreas(selection);
 
84
  return selection;
82
85
}
83
86
 
84
87
bool KSpreadSelection::singleCellSelection() const
85
88
{
86
89
  const KSpreadCell* cell =
87
 
    m_pView->activeTable()->cellAt(m_marker.x(), m_marker.y());
 
90
    m_pView->activeSheet()->cellAt(m_marker.x(), m_marker.y());
88
91
 
89
92
  QRect currentSelection = selection();
90
93
  return ((currentSelection.topLeft() == m_marker) &&
108
111
    column = selection().right();
109
112
    row = selection().bottom();
110
113
  }
111
 
  const KSpreadCell* cell = m_pView->activeTable()->cellAt(column, row);
 
114
  const KSpreadCell* cell = m_pView->activeSheet()->cellAt(column, row);
112
115
 
113
 
  double xpos = m_pView->activeTable()->dblColumnPos( column );
114
 
  double ypos = m_pView->activeTable()->dblRowPos( row );
 
116
  double xpos = m_pView->activeSheet()->dblColumnPos( column );
 
117
  double ypos = m_pView->activeSheet()->dblRowPos( row );
115
118
  double width = cell->dblWidth( column );
116
119
  double height = cell->dblHeight( row );
117
120
 
127
130
 
128
131
void KSpreadSelection::setSelection( const QPoint &newMarker,
129
132
                                     const QPoint &newAnchor,
130
 
                                     KSpreadSheet *table )
 
133
                                     KSpreadSheet *sheet )
131
134
{
132
135
  QRect oldSelection = selection();
133
136
  QPoint oldMarker = m_marker;
136
139
 
137
140
  QRect newSelection = selection();
138
141
 
139
 
  const KSpreadCell* cell = table->cellAt(newMarker);
 
142
  //kdDebug(36001) << "setSelection: anchor = " << newAnchor
 
143
  //             << " marker = " << newMarker << endl;
 
144
 
 
145
  const KSpreadCell* cell = sheet->cellAt(newMarker);
140
146
  if (!util_isColumnSelected(newSelection) &&
141
147
      !util_isRowSelected(newSelection) &&
142
148
      cell->isObscured() && cell->isObscuringForced())
149
155
 
150
156
  /* see if we've actually changed anything */
151
157
  if ( newSelection == oldSelection && newMarker == oldMarker &&
152
 
       m_pView->activeTable() == table )
 
158
       m_pView->activeSheet() == sheet )
153
159
    return;
154
160
 
155
161
  /* see if the cursor position is still valid */
160
166
 
161
167
  m_pView->enableInsertColumn( !util_isRowSelected( newSelection ) );
162
168
  m_pView->enableInsertRow( !util_isColumnSelected( newSelection ) );
163
 
  m_pView->slotChangeSelection( table, oldSelection, oldMarker );
 
169
  m_pView->slotChangeSelection( sheet, oldSelection, oldMarker );
164
170
}
165
171
 
166
172
void KSpreadSelection::setMarker( const QPoint &point,
167
 
                                  KSpreadSheet* table )
 
173
                                  KSpreadSheet* sheet )
168
174
{
169
175
  QPoint topLeft(point);
170
 
  const KSpreadCell* cell = table->cellAt(topLeft);
 
176
  const KSpreadCell* cell = sheet->cellAt(topLeft);
171
177
  if (cell->isObscured() && cell->isObscuringForced())
172
178
  {
173
179
    cell = cell->obscuringCells().first();
176
182
 
177
183
  QPoint botRight(topLeft.x() + cell->extraXCells(),
178
184
                  topLeft.y() + cell->extraYCells());
179
 
  setSelection( topLeft, botRight, table );
 
185
  setSelection( topLeft, botRight, sheet );
180
186
}
181
187
 
182
188
QPoint KSpreadSelection::selectionAnchor()const
196
202
  QPoint anchor(atLeft ? m_rctSelection.right() : m_rctSelection.left(),
197
203
                atTop ? m_rctSelection.bottom() : m_rctSelection.top());
198
204
 
199
 
  KSpreadSheet* table = m_pView->activeTable();
200
 
  KSpreadCell* cell = table->cellAt(anchor);
 
205
  KSpreadSheet* sheet = m_pView->activeSheet();
 
206
  KSpreadCell* cell = sheet->cellAt(anchor);
201
207
 
202
208
  if (cell->isObscured())
203
209
  {
215
221
 
216
222
bool KSpreadSelection::setCursorPosition( const QPoint &position )
217
223
{
218
 
  const KSpreadCell* cell = m_pView->activeTable()->cellAt(m_marker);
 
224
  const KSpreadCell* cell = m_pView->activeSheet()->cellAt(m_marker);
219
225
 
220
226
  QRect markerArea(m_marker, QPoint(m_marker.x() + cell->mergedXCells(),
221
227
                                    m_marker.y() + cell->mergedYCells()));
249
255
 
250
256
QRect KSpreadSelection::extendToMergedAreas(QRect area) const
251
257
{
252
 
  const KSpreadCell *cell = m_pView->activeTable()->
 
258
  const KSpreadCell *cell = m_pView->activeSheet()->
253
259
                            cellAt(area.left(), area.top());
254
260
 
255
261
  if( util_isColumnSelected(area) ||
277
283
    for ( int x = area.left(); x <= area.right(); x++ )
278
284
      for ( int y = area.top(); y <= area.bottom(); y++ )
279
285
      {
280
 
        cell = m_pView->activeTable()->cellAt( x, y );
 
286
        cell = m_pView->activeSheet()->cellAt( x, y );
281
287
        if( cell->isForceExtraCells())
282
288
        {
283
289
          right=QMAX(right,cell->extraXCells()+x);