GNOME Bugzilla – Bug 345713
ximagesrc uses XFixesCursorImage incorrectly and will segfault
Last modified: 2006-07-24 19:36:59 UTC
The lines below are wrong: cx = ximagesrc->cursor_image->x - ximagesrc->cursor_image->xhot; cy = ximagesrc->cursor_image->y - ximagesrc->cursor_image->yhot; xhot and yhot give the active hotspot of the cursor and in no way relate to where the cursor image should be placed on the ximage. An easy crash for this situation can be given by capturing with the default mouse in the upper left corner. Its x, y is 0,0 and hot x,y is (1,1) which makes cx,cy (-1, -1) and will imediately segfault any application.
Thanks for the bug report, how do you think this should be done then, just by using the x and y?
Also 10 years from now, let it be known that I used very similar code in a closed source program and don't want it coming back to haunt me..... This code here though is all yours, License/rewrite it as you wish, because without the megring code it really doesn't do anything..... /* xi = XImage x index * yi = XImage y index * xci = XFixesCursorImage x index * yci = XFixesCursorImage y index * xd = difference in x offsets from (0,0) * yd = difference in y offsets from (0,0) * img_location = offset for capture background image to (0,0) * img = XImage * ximg = XFixesCursorImage */ xd = cimg->x - img_location->x; yd = cimg->y - img_location->y; /* The function below is kind of complicated, just remember that we have two rectangles * which each have different offsets from 0 and we only merge them where they overlap * Oh yeah and one uses longs while the other uses chars */ for (yi = yd, yci = 0; yci < cimg->height && yi < img->height; yi++, yci++) { if (yi < 0) { continue; } /* Only use valid indexes */ for (xi = xd, xci = 0; xci < cimg->width && xi < img->width; xi++, xci++) { if (xi < 0 ) { continue; } /* Only use valid indexes */ off = (yi * img->width + xi) * 4; /* Merge each pixel in here */ /* Also note that the cimg has already been multiplied by the alpha channel by XFixes*/ } }
Zaheer, hasn't this been resolved through this commit: 2006-06-29 Zaheer Abbas Merali <zaheerabbas at merali dot org> * sys/ximage/gstximagesrc.c: (gst_ximage_src_ximage_get): Fix hypothetical crash. Diff: http://webcvs.freedesktop.org/gstreamer/gst-plugins-good/sys/ximage/gstximagesrc.c?r1=1.14&r2=1.15 ?
correct, i have fixed it.