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

« back to all changes in this revision

Viewing changes to kpresenter/kpobjectproperties.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:
 
1
// -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
 
2
/* This file is part of the KDE project
 
3
   Copyright (C) 2005 Thorsten Zachmann <zachmann@kde.org>
 
4
 
 
5
   This library is free software; you can redistribute it and/or
 
6
   modify it under the terms of the GNU Library General Public
 
7
   License as published by the Free Software Foundation; either
 
8
   version 2 of the License, or (at your option) any later version.
 
9
 
 
10
   This library is distributed in the hope that it will be useful,
 
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
   Library General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU Library General Public License
 
16
   along with this library; see the file COPYING.LIB.  If not, write to
 
17
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
18
   Boston, MA 02111-1307, USA.
 
19
*/
 
20
 
 
21
#include "kpobjectproperties.h"
 
22
 
 
23
#include "kpobject.h"
 
24
#include "kpcubicbeziercurveobject.h"
 
25
#include "kpgroupobject.h"
 
26
#include "kplineobject.h"
 
27
#include "kprectobject.h"
 
28
#include "kppolygonobject.h"
 
29
#include "kppieobject.h"
 
30
#include "kppixmapobject.h"
 
31
#include "kppointobject.h"
 
32
#include "kpquadricbeziercurveobject.h"
 
33
#include "kptextobject.h"
 
34
 
 
35
KPObjectProperties::KPObjectProperties( const QPtrList<KPObject> &objects )
 
36
: m_objects( objects )
 
37
, m_flags( 0 )
 
38
, m_pen( QPen( Qt::black, 1, Qt::SolidLine ), L_NORMAL, L_NORMAL )
 
39
, m_protectContent( STATE_UNDEF )
 
40
{
 
41
    getProperties( m_objects );
 
42
}
 
43
 
 
44
 
 
45
KPObjectProperties::~KPObjectProperties()
 
46
{
 
47
}
 
48
 
 
49
 
 
50
void KPObjectProperties::getProperties( const QPtrList<KPObject> &objects )
 
51
{
 
52
    QPtrListIterator<KPObject> it( objects );
 
53
    for ( ; it.current() ; ++it )
 
54
    {
 
55
        switch ( it.current()->getType() )
 
56
        {
 
57
            case OT_LINE:
 
58
                getPenProperties( it.current() );
 
59
                getLineEndsProperties( it.current() );
 
60
                m_flags |= PtOther;
 
61
                break;
 
62
            case OT_FREEHAND:
 
63
            case OT_POLYLINE:
 
64
                getPenProperties( it.current() );
 
65
                if( !static_cast<KPPointObject*>( it.current() )->isClosed() )
 
66
                    getLineEndsProperties( it.current() );
 
67
                m_flags |= PtOther;
 
68
                break;
 
69
            case OT_QUADRICBEZIERCURVE:
 
70
                getPenProperties( it.current() );
 
71
                if ( !static_cast<KPQuadricBezierCurveObject*>( it.current() )->isClosed() )
 
72
                    getLineEndsProperties( it.current() );
 
73
                m_flags |= PtOther;
 
74
                break;
 
75
            case OT_CUBICBEZIERCURVE:
 
76
                getPenProperties( it.current() );
 
77
                if ( !static_cast<KPCubicBezierCurveObject*>( it.current() )->isClosed() )
 
78
                    getLineEndsProperties( it.current() );
 
79
                m_flags |= PtOther;
 
80
                break;
 
81
            case OT_PIE:
 
82
                getPieProperties( it.current() );
 
83
                break;
 
84
            case OT_RECT:
 
85
                getRectProperties( it.current() );
 
86
                break;
 
87
            case OT_POLYGON:
 
88
                getPolygonSettings( it.current() );
 
89
                break;
 
90
            case OT_TEXT:
 
91
                getTextProperties( it.current() );
 
92
                break;
 
93
            case OT_PART:
 
94
            case OT_ELLIPSE:
 
95
            case OT_CLOSED_LINE:
 
96
            case OT_AUTOFORM:
 
97
                getPenProperties( it.current() );
 
98
                getBrushProperties( it.current() );
 
99
                m_flags |= PtOther;
 
100
                break;
 
101
            case OT_CLIPART:
 
102
            case OT_PICTURE:
 
103
                getPictureProperties( it.current() );
 
104
                break;
 
105
            case OT_GROUP:
 
106
                {
 
107
                    KPGroupObject *obj = dynamic_cast<KPGroupObject*>( it.current() );
 
108
                    if ( obj )
 
109
                    {
 
110
                        getProperties( obj->objectList() );
 
111
                    }
 
112
                }
 
113
                break;
 
114
            default:
 
115
                break;
 
116
        }
 
117
    }
 
118
}
 
119
 
 
120
 
 
121
void KPObjectProperties::getPenProperties( KPObject *object )
 
122
{
 
123
    if ( !( m_flags & PtPen ) )
 
124
    {
 
125
        KPShadowObject *obj = dynamic_cast<KPShadowObject*>( object );
 
126
        if ( obj )
 
127
        {
 
128
            m_pen.pen = obj->getPen();
 
129
 
 
130
            m_flags |= PtPen;
 
131
        }
 
132
    }
 
133
}
 
134
 
 
135
 
 
136
void KPObjectProperties::getLineEndsProperties( KPObject *object )
 
137
{
 
138
    if ( !( m_flags & PtLineEnds ) )
 
139
    {
 
140
        switch ( object->getType() )
 
141
        {
 
142
            case OT_LINE:
 
143
                {
 
144
                    KPLineObject *obj = dynamic_cast<KPLineObject*>( object );
 
145
                    if ( obj )
 
146
                    {
 
147
                        m_pen.lineBegin = obj->getLineBegin();
 
148
                        m_pen.lineEnd = obj->getLineEnd();
 
149
 
 
150
                        m_flags |= PtLineEnds;
 
151
                    }
 
152
                    break;
 
153
                }
 
154
            case OT_FREEHAND:
 
155
            case OT_POLYLINE:
 
156
            case OT_QUADRICBEZIERCURVE:
 
157
            case OT_CUBICBEZIERCURVE:
 
158
                {
 
159
                    KPPointObject *obj = dynamic_cast<KPPointObject*>( object );
 
160
                    if ( obj )
 
161
                    {
 
162
                        m_pen.lineBegin = obj->getLineBegin();
 
163
                        m_pen.lineEnd = obj->getLineEnd();
 
164
 
 
165
                        m_flags |= PtLineEnds;
 
166
                    }
 
167
                    break;
 
168
                }
 
169
            default:
 
170
                break;
 
171
        }
 
172
    }
 
173
}
 
174
 
 
175
 
 
176
void KPObjectProperties::getBrushProperties( KPObject *object )
 
177
{
 
178
    if ( !( m_flags & PtBrush ) )
 
179
    {
 
180
        KP2DObject * obj = dynamic_cast<KP2DObject*>( object );
 
181
        if ( obj )
 
182
        {
 
183
            m_brush.brush = obj->getBrush();
 
184
            m_brush.fillType = obj->getFillType();
 
185
            m_brush.gColor1 = obj->getGColor1();
 
186
            m_brush.gColor2 = obj->getGColor2();
 
187
            m_brush.gType = obj->getGType();
 
188
            m_brush.unbalanced = obj->getGUnbalanced();
 
189
            m_brush.xfactor = obj->getGXFactor();
 
190
            m_brush.yfactor = obj->getGYFactor();
 
191
 
 
192
            m_flags |= PtBrush;
 
193
        }
 
194
    }
 
195
}
 
196
 
 
197
 
 
198
void KPObjectProperties::getRectProperties( KPObject *object )
 
199
{
 
200
    if ( !( m_flags & PtRectangle ) )
 
201
    {
 
202
        KPRectObject *obj = dynamic_cast<KPRectObject*>( object );
 
203
        if ( obj )
 
204
        {
 
205
            obj->getRnds( m_rectValues.xRnd, m_rectValues.yRnd );
 
206
 
 
207
            getPenProperties( object );
 
208
            getBrushProperties( object );
 
209
            m_flags |= PtRectangle;
 
210
        }
 
211
    }
 
212
}
 
213
 
 
214
 
 
215
void KPObjectProperties::getPolygonSettings( KPObject *object )
 
216
{
 
217
    if ( !( m_flags & PtPolygon ) )
 
218
    {
 
219
        KPPolygonObject *obj = dynamic_cast<KPPolygonObject*>( object );
 
220
        if ( obj )
 
221
        {
 
222
            m_polygonSettings.checkConcavePolygon = obj->getCheckConcavePolygon();
 
223
            m_polygonSettings.cornersValue = obj->getCornersValue();
 
224
            m_polygonSettings.sharpnessValue = obj->getSharpnessValue();
 
225
 
 
226
            getPenProperties( object );
 
227
            getBrushProperties( object );
 
228
            m_flags |= PtPolygon;
 
229
        }
 
230
    }
 
231
}
 
232
 
 
233
 
 
234
void KPObjectProperties::getPieProperties( KPObject *object )
 
235
{
 
236
    if ( !( m_flags & PtPie ) )
 
237
    {
 
238
        KPPieObject *obj = dynamic_cast<KPPieObject*>( object );
 
239
        if ( obj )
 
240
        {
 
241
            m_pieValues.pieType = obj->getPieType();
 
242
            m_pieValues.pieAngle = obj->getPieAngle();
 
243
            m_pieValues.pieLength = obj->getPieLength();
 
244
 
 
245
            getPenProperties( object );
 
246
            if ( obj->getPieType() != PT_ARC )
 
247
                getBrushProperties( object );
 
248
 
 
249
            m_flags |= PtPie;
 
250
        }
 
251
    }
 
252
}
 
253
 
 
254
 
 
255
void KPObjectProperties::getPictureProperties( KPObject *object )
 
256
{
 
257
    if ( !( m_flags & PtPicture ) )
 
258
    {
 
259
        KPPixmapObject *obj = dynamic_cast<KPPixmapObject*>( object );
 
260
        if ( obj )
 
261
        {
 
262
            m_pictureSettings.mirrorType = obj->getPictureMirrorType();
 
263
            m_pictureSettings.depth = obj->getPictureDepth();
 
264
            m_pictureSettings.swapRGB = obj->getPictureSwapRGB();
 
265
            m_pictureSettings.grayscal = obj->getPictureGrayscal();
 
266
            m_pictureSettings.bright = obj->getPictureBright();
 
267
            m_pixmap = obj->getOriginalPixmap();
 
268
 
 
269
            getPenProperties( object );
 
270
            getBrushProperties( object );
 
271
            m_flags |= PtPicture;
 
272
        }
 
273
    }
 
274
}
 
275
 
 
276
 
 
277
void KPObjectProperties::getTextProperties( KPObject *object )
 
278
{
 
279
    KPTextObject *obj = dynamic_cast<KPTextObject*>( object );
 
280
    if ( obj )
 
281
    {
 
282
        if ( !( m_flags & PtText ) )
 
283
        {
 
284
            m_marginsStruct = MarginsStruct( obj );
 
285
            m_protectContent = obj->isProtectContent() ? STATE_ON : STATE_OFF;
 
286
 
 
287
            getPenProperties( object );
 
288
            getBrushProperties( object );
 
289
            m_flags |= PtText;
 
290
        }
 
291
        else
 
292
        {
 
293
            PropValue pv = obj->isProtectContent() ? STATE_ON : STATE_OFF;
 
294
            if ( pv != m_protectContent )
 
295
            {
 
296
                m_protectContent = STATE_UNDEF;
 
297
            }
 
298
        }
 
299
    }
 
300
}