Merge lp:~3v1n0/compiz/ignore-invalid-sized-textures into lp:compiz/0.9.11

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Christopher Townsend
Approved revision: 3836
Merged at revision: 3834
Proposed branch: lp:~3v1n0/compiz/ignore-invalid-sized-textures
Merge into: lp:compiz/0.9.11
Diff against target: 198 lines (+54/-33)
2 files modified
debian/patches/100_workaround_virtualbox_hang.patch (+32/-25)
plugins/opengl/src/texture.cpp (+22/-8)
To merge this branch: bzr merge lp:~3v1n0/compiz/ignore-invalid-sized-textures
Reviewer Review Type Date Requested Status
Christopher Townsend Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+209061@code.launchpad.net

Commit message

Opengl, Texture: don't try to create a texture of invalid (empty or negative) size

This seem to cause also a crash when using software rendering.

Description of the change

There's no reason to create textures of 0x0 size, we can just return an empty list in this case.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Sam Spilsbury (smspillaz) wrote :
Download full text (3.4 KiB)

Ouch that's nasty.

One thing to consider is that I don't think it is possible for a
Drawable to have a zero or negative size. Taken from the manpage for
XCreatePixmap for instance:

"The width and height arguments must be nonzero, or a BadValue error results."

As such, if bindPixmapToTexture is called with a zero or negative
size, it is almost certainly programmer error. I would think that a
warning should be printed here or that an assertion should be fired.
Just returning an empty list runs the danger of this programmer error
(which can have quite serious results) being silently ignored, which
might cause more subtle problems later down the line.

(I'd also have a look at unity::UnityWindow::DrawWindowDecoration,
because it seems like the bad value is coming from there).

On Mon, Mar 3, 2014 at 8:54 PM, Marco Trevisan (Treviño) <mail@3v1n0.net> wrote:
> Marco Trevisan (Treviño) has proposed merging lp:~3v1n0/compiz/ignore-invalid-sized-textures into lp:compiz.
>
> Commit message:
> Opengl, Texture: don't try to create a texture of invalid (empty or negative) size
>
> This seem to cause also a crash when using software rendering.
>
> Requested reviews:
> Compiz Maintainers (compiz-team)
> Related bugs:
> Bug #1055166 in Compiz: "compiz crashed with SIGSEGV in memmove() from drisw_update_tex_buffer() from dri_set_tex_buffer2() from operator() from compiz::opengl::bindTexImageGLX() from ... from unity::UnityWindow::DrawWindowDecoration"
> https://bugs.launchpad.net/compiz/+bug/1055166
>
> For more details, see:
> https://code.launchpad.net/~3v1n0/compiz/ignore-invalid-sized-textures/+merge/209061
>
> There's no reason to create textures of 0x0 size, we can just return an empty list in this case.
> --
> https://code.launchpad.net/~3v1n0/compiz/ignore-invalid-sized-textures/+merge/209061
> Your team Compiz Maintainers is requested to review the proposed merge of lp:~3v1n0/compiz/ignore-invalid-sized-textures into lp:compiz.
>
> === modified file 'plugins/opengl/src/texture.cpp'
> --- plugins/opengl/src/texture.cpp 2012-09-19 12:18:34 +0000
> +++ plugins/opengl/src/texture.cpp 2014-03-03 12:53:46 +0000
> @@ -433,6 +433,12 @@
> int depth,
> compiz::opengl::PixmapSource source)
> {
> + if (!GL::textureFromPixmap || width <= 0 || height <= 0 ||
> + width > GL::maxTextureSize || height > GL::maxTextureSize)
> + {
> + return GLTexture::List ();
> + }
> +
> GLTexture::List rv;
>
> foreach (BindPixmapProc &proc, GLScreen::get (screen)->priv->bindPixmap)
> @@ -473,10 +479,6 @@
> int depth,
> compiz::opengl::PixmapSource source)
> {
> - if ((int) width > GL::maxTextureSize || (int) height > GL::maxTextureSize ||
> - !GL::textureFromPixmap)
> - return GLTexture::List ();
> -
> GLTexture::List rv (1);
> EglTexture *tex = NULL;
> EGLImageKHR eglImage = NULL;
> @@ -644,10 +646,6 @@
> int depth,
> cgl::Pixmap...

Read more...

3834. By Marco Trevisan (Treviño)

debian/patches/100_workaround_virtualbox_hang.patch: refresh to apply in current trunk

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

> As such, if bindPixmapToTexture is called with a zero or negative
> size, it is almost certainly programmer error. I would think that a
> warning should be printed here or that an assertion should be fired.
> Just returning an empty list runs the danger of this programmer error
> (which can have quite serious results) being silently ignored, which
> might cause more subtle problems later down the line.

Right.

> (I'd also have a look at unity::UnityWindow::DrawWindowDecoration,
> because it seems like the bad value is coming from there).

Yeah, that's already done, but I'd also prefer to avoid this to happen.

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

On Mon, Mar 3, 2014 at 10:36 PM, Marco Trevisan (Treviño)
<mail@3v1n0.net> wrote:
>> As such, if bindPixmapToTexture is called with a zero or negative
>> size, it is almost certainly programmer error. I would think that a
>> warning should be printed here or that an assertion should be fired.
>> Just returning an empty list runs the danger of this programmer error
>> (which can have quite serious results) being silently ignored, which
>> might cause more subtle problems later down the line.
>
> Right.
>
>> (I'd also have a look at unity::UnityWindow::DrawWindowDecoration,
>> because it seems like the bad value is coming from there).
>
> Yeah, that's already done, but I'd also prefer to avoid this to happen.

Yep, sounds good. Not crashing with explanation and a warning is
definitely better than crashing without explanation where a runtime
contract exists.

> --
> https://code.launchpad.net/~3v1n0/compiz/ignore-invalid-sized-textures/+merge/209061
> Your team Compiz Maintainers is requested to review the proposed merge of lp:~3v1n0/compiz/ignore-invalid-sized-textures into lp:compiz.

--
Sam Spilsbury

3835. By Marco Trevisan (Treviño)

OpenGL, Texture: log about errors in case texture binding is wrong

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
3836. By Marco Trevisan (Treviño)

OpenGL, Texture: fix indentation change

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Christopher Townsend (townsend) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/patches/100_workaround_virtualbox_hang.patch'
2--- debian/patches/100_workaround_virtualbox_hang.patch 2013-05-10 16:10:55 +0000
3+++ debian/patches/100_workaround_virtualbox_hang.patch 2014-03-03 16:20:39 +0000
4@@ -1,6 +1,8 @@
5---- a/plugins/opengl/include/opengl/opengl.h
6-+++ b/plugins/opengl/include/opengl/opengl.h
7-@@ -582,6 +582,17 @@
8+Index: compiz/plugins/opengl/include/opengl/opengl.h
9+===================================================================
10+--- compiz.orig/plugins/opengl/include/opengl/opengl.h 2014-03-03 15:29:29.898235681 +0100
11++++ compiz/plugins/opengl/include/opengl/opengl.h 2014-03-03 15:29:29.894235669 +0100
12+@@ -590,6 +590,17 @@
13
14 extern GLScreenPaintAttrib defaultScreenPaintAttrib;
15
16@@ -18,7 +20,7 @@
17 class GLScreen;
18 class GLFramebufferObject;
19 class GLScreenInterface;
20-@@ -774,6 +785,13 @@
21+@@ -787,6 +798,13 @@
22
23 bool glInitContext (XVisualInfo *);
24
25@@ -32,8 +34,10 @@
26 WRAPABLE_HND (0, GLScreenInterface, bool, glPaintOutput,
27 const GLScreenPaintAttrib &, const GLMatrix &,
28 const CompRegion &, CompOutput *, unsigned int);
29---- a/plugins/opengl/src/privates.h
30-+++ b/plugins/opengl/src/privates.h
31+Index: compiz/plugins/opengl/src/privates.h
32+===================================================================
33+--- compiz.orig/plugins/opengl/src/privates.h 2014-03-03 15:29:29.898235681 +0100
34++++ compiz/plugins/opengl/src/privates.h 2014-03-03 15:29:29.894235669 +0100
35 @@ -47,6 +47,24 @@
36
37 extern CompOutput *targetOutput;
38@@ -59,15 +63,15 @@
39 class GLDoubleBuffer :
40 public compiz::opengl::DoubleBuffer
41 {
42-@@ -123,6 +141,7 @@
43- class PrivateGLScreen :
44+@@ -141,6 +159,7 @@
45 public ScreenInterface,
46+ public CompositeScreenInterface,
47 public compiz::composite::PaintHandler,
48 + public compiz::opengl::internal::DriverWorkaroundQuery,
49 public OpenglOptions
50 {
51 public:
52-@@ -207,6 +226,7 @@
53+@@ -232,6 +251,7 @@
54 std::vector<GLTexture::BindPixmapProc> bindPixmap;
55 bool hasCompositing;
56 bool commonFrontbuffer;
57@@ -75,8 +79,8 @@
58 bool incorrectRefreshRate; // hack for NVIDIA specifying an incorrect
59 // refresh rate, causing us to miss vblanks
60
61-@@ -226,6 +246,10 @@
62-
63+@@ -253,6 +273,10 @@
64+ bool postprocessingRequired;
65 mutable CompString prevRegex;
66 mutable bool prevBlacklisted;
67 +
68@@ -86,8 +90,10 @@
69 };
70
71 class PrivateGLWindow :
72---- a/plugins/opengl/src/screen.cpp
73-+++ b/plugins/opengl/src/screen.cpp
74+Index: compiz/plugins/opengl/src/screen.cpp
75+===================================================================
76+--- compiz.orig/plugins/opengl/src/screen.cpp 2014-03-03 15:29:29.898235681 +0100
77++++ compiz/plugins/opengl/src/screen.cpp 2014-03-03 15:29:29.894235669 +0100
78 @@ -67,6 +67,7 @@
79
80
81@@ -96,8 +102,8 @@
82
83 namespace GL {
84 #ifdef USE_GLES
85-@@ -359,6 +360,18 @@
86- #endif
87+@@ -537,6 +538,18 @@
88+ };
89
90 bool
91 +PrivateGLScreen::unsafeForExternalBinds () const
92@@ -115,7 +121,7 @@
93 GLScreen::glInitContext (XVisualInfo *visinfo)
94 {
95 #ifndef USE_GLES
96-@@ -660,6 +673,7 @@
97+@@ -855,6 +868,7 @@
98
99 priv->commonFrontbuffer = true;
100 priv->incorrectRefreshRate = false;
101@@ -123,7 +129,7 @@
102 if (glRenderer != NULL && strstr (glRenderer, "on llvmpipe"))
103 {
104 /*
105-@@ -680,6 +694,18 @@
106+@@ -875,6 +889,18 @@
107 priv->incorrectRefreshRate = true;
108 }
109
110@@ -142,8 +148,10 @@
111 if (strstr (glExtensions, "GL_ARB_texture_non_power_of_two"))
112 GL::textureNonPowerOfTwo = true;
113 GL::textureNonPowerOfTwoMipmap = GL::textureNonPowerOfTwo;
114---- a/plugins/opengl/src/texture.cpp
115-+++ b/plugins/opengl/src/texture.cpp
116+Index: compiz/plugins/opengl/src/texture.cpp
117+===================================================================
118+--- compiz.orig/plugins/opengl/src/texture.cpp 2014-03-03 15:29:29.898235681 +0100
119++++ compiz/plugins/opengl/src/texture.cpp 2014-03-03 15:31:45.974666737 +0100
120 @@ -41,6 +41,7 @@
121 #include "glx-tfp-bind.h"
122
123@@ -152,15 +160,14 @@
124
125 #ifdef USE_GLES
126 std::map<Damage, EglTexture*> boundPixmapTex;
127-@@ -648,6 +649,13 @@
128- !GL::textureFromPixmap)
129- return GLTexture::List ();
130-
131+@@ -646,6 +647,12 @@
132+ int depth,
133+ cgl::PixmapSource source)
134+ {
135 + GLScreen *gs = GLScreen::get (screen);
136 + const cglint::DriverWorkaroundQuery &query (gs->fetchDriverWorkarounds ());
137 +
138-+ if (query.unsafeForExternalBinds () &&
139-+ source == cgl::ExternallyManaged)
140++ if (query.unsafeForExternalBinds () && source == cgl::ExternallyManaged)
141 + return GLTexture::List ();
142 +
143 GLTexture::List rv (1);
144
145=== modified file 'plugins/opengl/src/texture.cpp'
146--- plugins/opengl/src/texture.cpp 2012-09-19 12:18:34 +0000
147+++ plugins/opengl/src/texture.cpp 2014-03-03 16:20:39 +0000
148@@ -433,6 +433,28 @@
149 int depth,
150 compiz::opengl::PixmapSource source)
151 {
152+ if (!GL::textureFromPixmap)
153+ {
154+ compLogMessage("opengl", CompLogLevelError,
155+ "GL::textureFromPixmap is not supported.");
156+ }
157+
158+ if (width <= 0 || height <= 0)
159+ {
160+ compLogMessage("opengl", CompLogLevelError,
161+ "Couldn't bind 0-sized pixmap to texture: "
162+ "the width and height arguments must be nonzero.");
163+ return GLTexture::List ();
164+ }
165+
166+ if (width > GL::maxTextureSize || height > GL::maxTextureSize)
167+ {
168+ compLogMessage("opengl", CompLogLevelError,
169+ "Impossible to bind a pixmap bigger than %dx%d to texture.",
170+ GL::maxTextureSize, GL::maxTextureSize);
171+ return GLTexture::List ();
172+ }
173+
174 GLTexture::List rv;
175
176 foreach (BindPixmapProc &proc, GLScreen::get (screen)->priv->bindPixmap)
177@@ -473,10 +495,6 @@
178 int depth,
179 compiz::opengl::PixmapSource source)
180 {
181- if ((int) width > GL::maxTextureSize || (int) height > GL::maxTextureSize ||
182- !GL::textureFromPixmap)
183- return GLTexture::List ();
184-
185 GLTexture::List rv (1);
186 EglTexture *tex = NULL;
187 EGLImageKHR eglImage = NULL;
188@@ -644,10 +662,6 @@
189 int depth,
190 cgl::PixmapSource source)
191 {
192- if ((int) width > GL::maxTextureSize || (int) height > GL::maxTextureSize ||
193- !GL::textureFromPixmap)
194- return GLTexture::List ();
195-
196 GLTexture::List rv (1);
197 TfpTexture *tex = NULL;
198 unsigned int target = 0;

Subscribers

People subscribed via source and target branches