[PATCH] Check size when generating FrameSvg background

2009-12-22 Thread Aurélien Gâteau
(reviewboard seems to be down today, so sending this the old-fashioned way)

Hi,

Stumbled upon a bad_alloc exception in Plasma today: after some
debugging I found out that sometimes
FrameSvgPrivate::generateFrameBackground() tried to generate a
background of size 16777215 x 13. 16777215 is QWIDGETSIZE_MAX.

It seems the buggy size comes from the way the System Monitor applet
uses Plasma::Frame, but I thought adding a generic guard in
generateFrameBackground() would be useful, hence the attached patch.

Actually I am thinking it may make sense to set stricter limits, for
example ensuring each dimension is less than say 1 pixels.

What do you think about this?

Aurélien
diff --git a/plasma/framesvg.cpp b/plasma/framesvg.cpp
index 981e8fa..611acc0 100644
--- a/plasma/framesvg.cpp
+++ b/plasma/framesvg.cpp
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -490,6 +491,10 @@ void FrameSvgPrivate::generateFrameBackground(FrameData *frame)
 kWarning() << "Invalid frame size" << size;
 return;
 }
+if (size.width() == QWIDGETSIZE_MAX || size.height() == QWIDGETSIZE_MAX) {
+kWarning() << "Not generating frame background for a size whose width or height is QWIDGETSIZE_MAX" << size;
+return;
+}
 
 const int contentWidth = size.width() - frame->leftWidth  - frame->rightWidth;
 const int contentHeight = size.height() - frame->topHeight  - frame->bottomHeight;
___
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel


Re: [PATCH] Check size when generating FrameSvg background

2009-12-22 Thread Marco Martin
On Tuesday 22 December 2009, Aurélien Gâteau wrote:
> (reviewboard seems to be down today, so sending this the old-fashioned way)
> 
> Hi,
> 
> Stumbled upon a bad_alloc exception in Plasma today: after some
> debugging I found out that sometimes
> FrameSvgPrivate::generateFrameBackground() tried to generate a
> background of size 16777215 x 13. 16777215 is QWIDGETSIZE_MAX.
> 
> It seems the buggy size comes from the way the System Monitor applet
> uses Plasma::Frame, but I thought adding a generic guard in
> generateFrameBackground() would be useful, hence the attached patch.
> 
> Actually I am thinking it may make sense to set stricter limits, for
> example ensuring each dimension is less than say 1 pixels.
> 
> What do you think about this?
> 
> Aurélien
> 
well, with this patch it would still break with qwidgetsizemax-1 :p
so yeah a stricter limit would probably make sense, perhaps as a const int in 
framesvgprivate

-- 
Marco Martin
___
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel


Re: [PATCH] Check size when generating FrameSvg background

2009-12-22 Thread Aurélien Gâteau
Marco Martin wrote:
> On Tuesday 22 December 2009, Aurélien Gâteau wrote:
>> (reviewboard seems to be down today, so sending this the old-fashioned way)
>>
>> Hi,
>>
>> Stumbled upon a bad_alloc exception in Plasma today: after some
>> debugging I found out that sometimes
>> FrameSvgPrivate::generateFrameBackground() tried to generate a
>> background of size 16777215 x 13. 16777215 is QWIDGETSIZE_MAX.
>>
>> It seems the buggy size comes from the way the System Monitor applet
>> uses Plasma::Frame, but I thought adding a generic guard in
>> generateFrameBackground() would be useful, hence the attached patch.
>>
>> Actually I am thinking it may make sense to set stricter limits, for
>> example ensuring each dimension is less than say 1 pixels.
>>
>> What do you think about this?
>>
>> Aurélien
>>
> well, with this patch it would still break with qwidgetsizemax-1 :p
> so yeah a stricter limit would probably make sense, perhaps as a const int in 
> framesvgprivate
> 

Agreed, attached is an updated patch.

Aurélien
diff --git a/plasma/framesvg.cpp b/plasma/framesvg.cpp
index 981e8fa..5871a07 100644
--- a/plasma/framesvg.cpp
+++ b/plasma/framesvg.cpp
@@ -36,6 +36,10 @@
 namespace Plasma
 {
 
+// Any attempt to generate a frame whose width or height is larger than this
+// will be rejected
+static const int MAX_FRAME_SIZE = 10;
+
 FrameSvg::FrameSvg(QObject *parent)
 : Svg(parent),
   d(new FrameSvgPrivate(this))
@@ -490,6 +494,10 @@ void FrameSvgPrivate::generateFrameBackground(FrameData *frame)
 kWarning() << "Invalid frame size" << size;
 return;
 }
+if (size.width() >= MAX_FRAME_SIZE || size.height() >= MAX_FRAME_SIZE) {
+kWarning() << "Not generating frame background for a size whose width or height is more than" << MAX_FRAME_SIZE << size;
+return;
+}
 
 const int contentWidth = size.width() - frame->leftWidth  - frame->rightWidth;
 const int contentHeight = size.height() - frame->topHeight  - frame->bottomHeight;
___
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel


Re: [PATCH] Check size when generating FrameSvg background

2009-12-22 Thread Marco Martin
On Tuesday 22 December 2009, Aurélien Gâteau wrote:
> Marco Martin wrote:
> > On Tuesday 22 December 2009, Aurélien Gâteau wrote:
> >> (reviewboard seems to be down today, so sending this the old-fashioned
> >> way)
> >>
> >> Hi,
> >>
> >> Stumbled upon a bad_alloc exception in Plasma today: after some
> >> debugging I found out that sometimes
> >> FrameSvgPrivate::generateFrameBackground() tried to generate a
> >> background of size 16777215 x 13. 16777215 is QWIDGETSIZE_MAX.
> >>
> >> It seems the buggy size comes from the way the System Monitor applet
> >> uses Plasma::Frame, but I thought adding a generic guard in
> >> generateFrameBackground() would be useful, hence the attached patch.
> >>
> >> Actually I am thinking it may make sense to set stricter limits, for
> >> example ensuring each dimension is less than say 1 pixels.
> >>
> >> What do you think about this?
> >>
> >> Aurélien
> >
> > well, with this patch it would still break with qwidgetsizemax-1 :p
> > so yeah a stricter limit would probably make sense, perhaps as a const
> > int in framesvgprivate
> 
> Agreed, attached is an updated patch.
> 
> Aurélien
> 
good to go i think

-- 
Marco Martin
___
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel


Re: [PATCH] Check size when generating FrameSvg background

2009-12-22 Thread Aurélien Gâteau
Marco Martin wrote:
> On Tuesday 22 December 2009, Aurélien Gâteau wrote:
>> Marco Martin wrote:
>>> On Tuesday 22 December 2009, Aurélien Gâteau wrote:
 (reviewboard seems to be down today, so sending this the old-fashioned
 way)

 Hi,

 Stumbled upon a bad_alloc exception in Plasma today: after some
 debugging I found out that sometimes
 FrameSvgPrivate::generateFrameBackground() tried to generate a
 background of size 16777215 x 13. 16777215 is QWIDGETSIZE_MAX.

 It seems the buggy size comes from the way the System Monitor applet
 uses Plasma::Frame, but I thought adding a generic guard in
 generateFrameBackground() would be useful, hence the attached patch.

 Actually I am thinking it may make sense to set stricter limits, for
 example ensuring each dimension is less than say 1 pixels.

 What do you think about this?

 Aurélien
>>> well, with this patch it would still break with qwidgetsizemax-1 :p
>>> so yeah a stricter limit would probably make sense, perhaps as a const
>>> int in framesvgprivate
>> Agreed, attached is an updated patch.
>>
>> Aurélien
>>
> good to go i think

OK, it's in.

Aurélien
___
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel


Re: [PATCH] Check size when generating FrameSvg background

2009-12-22 Thread Aaron J. Seigo
On December 22, 2009, Aurélien Gâteau wrote:
> > good to go i think
> 
> OK, it's in.

nice catch :)

-- 
Aaron J. Seigo
humru othro a kohnu se
GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA  EE75 D6B7 2EB1 A7F1 DB43

KDE core developer sponsored by Qt Development Frameworks


signature.asc
Description: This is a digitally signed message part.
___
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel