Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 284852 - x11-libs/gtk+-2.14.7-r2: assertion failure & segfault calling gdk_screen_get_n_monitors() with invalid value
Summary: x11-libs/gtk+-2.14.7-r2: assertion failure & segfault calling gdk_screen_get_...
Status: RESOLVED NEEDINFO
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] GNOME (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Gentoo Linux Gnome Desktop Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-14 03:41 UTC by Longpoke
Modified: 2010-03-13 17:52 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Longpoke 2009-09-14 03:41:24 UTC
Reproducable: Always

I'm not sure if I should file this upstream, so here it is. If I call the gdk library function gdk_screen_get_n_monitors() with an invalid value such as 2 (on my system) or -1, an assertion failure followed by a segfault will occur:

$ python
Python 2.6.2 (r262:71600, Sep 10 2009, 14:38:15) 
[GCC 3.4.6 (Gentoo Hardened 3.4.6-r2 p1.6, ssp-3.4.6-1.0, pie-8.7.10)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygtk
>>> pygtk.require('2.0')
>>> import gtk
>>> gtk.gdk.Screen().get_n_monitors()
1
>>> gtk.gdk.Screen().get_monitor_geometry(0)
gtk.gdk.Rectangle(0, 0, 2560, 1024)
>>> gtk.gdk.Screen().get_monitor_geometry(-1)
__main__:1: GtkWarning: get_monitor: assertion `monitor_num >= 0' failed
Segmentation fault

$ python
Python 2.6.2 (r262:71600, Sep 10 2009, 14:38:15) 
[GCC 3.4.6 (Gentoo Hardened 3.4.6-r2 p1.6, ssp-3.4.6-1.0, pie-8.7.10)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygtk
>>> pygtk.require('2.0')
>>> import gtk
>>> gtk.gdk.Screen().get_monitor_geometry(1)
__main__:1: GtkWarning: get_monitor: assertion `monitor_num < screen_x11->n_monitors' failed
Segmentation fault

I made a simple test in plain C code and I get the exact same bug:

$ cat bug.c 
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
	GdkScreen *screen;
	GdkRectangle monitor_geometry;
	int screen_num;

	if (argc < 2)
		return 2;
	screen_num = atoi(argv[1]);

	gtk_init(&argc, &argv);
	screen = gdk_screen_get_default();
	printf("%d monitor(s)\n",
	       gdk_screen_get_n_monitors(screen));

	printf("stats of monitor %d:\n", screen_num);
	gdk_screen_get_monitor_geometry(screen, screen_num, &monitor_geometry);
	printf("pos: %d,%d\n", monitor_geometry.x, monitor_geometry.y);
	printf("dimensions: %d,%d\n", monitor_geometry.width,
	       monitor_geometry.height);

	return 0;
}

$ gcc -Wall -g bug.c -o bug `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0` && ./bug 0
1 monitor(s)
stats of monitor 0:
pos: 0,0
dimensions: 2560,1024

$ gcc -Wall -g bug.c -o bug `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0` && ./bug -1
1 monitor(s)
stats of monitor -1:

(bug:13764): Gdk-CRITICAL **: get_monitor: assertion `monitor_num >= 0' failed
Segmentation fault

$ gcc -Wall -g bug.c -o bug `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0` && ./bug 2
1 monitor(s)
stats of monitor 2:

(bug:13774): Gdk-CRITICAL **: get_monitor: assertion `monitor_num < screen_x11->n_monitors' failed
Segmentation fault


System information:

$ equery list gtk
[ Searching for package 'gtk' in all categories among: ]
 * installed packages
[I--] [  ] dev-python/pygtk-2.14.1-r1 (2)
[I--] [  ] dev-python/pygtksourceview-2.4.0 (2)
[I--] [  ] dev-ruby/ruby-gtk2-0.16.0-r4 (0)
[I--] [  ] dev-util/gtk-doc-am-1.10-r1 (0)
[I--] [  ] sci-calculators/qalculate-gtk-0.9.6-r1 (0)
[I--] [  ] x11-libs/gtk+-2.14.7-r2 (2)
[I--] [  ] x11-libs/gtksourceview-2.4.2 (2.0)

$ equery list glib
[ Searching for package 'glib' in all categories among: ]
 * installed packages
[I--] [  ] dev-libs/dbus-glib-0.76 (0)
[I--] [  ] dev-libs/glib-2.18.4-r1 (2)
[I--] [  ] dev-libs/poppler-glib-0.10.7 (0)
[I--] [  ] dev-ruby/ruby-glib2-0.16.0-r3 (0)
[I--] [  ] sys-libs/glibc-2.9_p20081201-r2 (2.2)
[I--] [  ] virtual/poppler-glib-0.10.7 (0)

$ emerge --info
Portage 2.1.6.13 (hardened/amd64, gcc-3.4.6, glibc-2.9_p20081201-r2, 2.6.28-hardened-r9 x86_64)
=================================================================
System uname: Linux-2.6.28-hardened-r9-x86_64-Intel-R-_Core-TM-2_Duo_CPU_T5750_@_2.00GHz-with-gentoo-1.12.11.1
Timestamp of tree: Sun, 13 Sep 2009 14:00:20 +0000
ccache version 2.4 [enabled]
app-shells/bash:     4.0_p28
dev-java/java-config: 2.1.8-r1
dev-lang/python:     2.6.2-r1
dev-python/pycrypto: 2.0.1-r8
dev-util/ccache:     2.4-r7
sys-apps/baselayout: 1.12.11.1
sys-apps/sandbox:    1.6-r2
sys-devel/autoconf:  2.13, 2.63-r1
sys-devel/automake:  1.8.5-r3, 1.9.6-r2, 1.10.2
sys-devel/binutils:  2.18-r3
sys-devel/gcc-config: 1.4.1
sys-devel/libtool:   1.5.26
virtual/os-headers:  2.6.27-r2
ACCEPT_KEYWORDS="amd64"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-fomit-frame-pointer -O2 -pipe -march=nocona"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/php/apache2-php5/ext-active/ /etc/php/cgi-php5/ext-active/ /etc/php/cli-php5/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/udev/rules.d /usr/X11R6/bin/startx"
CXXFLAGS="-fomit-frame-pointer -O2 -pipe -march=nocona"
DISTDIR="/usr/portage/distfiles"
FEATURES="ccache distlocks fixpackages parallel-fetch protect-owned sandbox sfperms strict unmerge-orphans userfetch webrsync-gpg"
GENTOO_MIRRORS="http://gentoo.arcticnetwork.ca/ http://gentoo.mirrors.tera-byte.com/ http://mirror.csclub.uwaterloo.ca/gentoo-distfiles/"
LANG="en_US.utf8"
LDFLAGS="-Wl,-O1"
MAKEOPTS="-j3"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/local/portage"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="X X509 a52 aac acpi alsa amd64 bash-completion berkdb bzip2 cairo cjk cli cracklib crypt dbus djvu dts flac gnome gtk hal hardened jpeg json justify live mad mmx mp3 nautilus nls nptl nptlonly opengl pam pcre perl pic png python quicktime readline ruby smp sse sse2 ssl ssse3 svg sysfs tcpd truetype unicode urandom vorbis wma x264 xorg xvid zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x 	ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 	trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" ELIBC="glibc" INPUT_DEVICES="evdev mouse keyboard synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" USERLAND="GNU" VIDEO_CARDS="radeonhd"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, FFLAGS, INSTALL_MASK, LC_ALL, LINGUAS, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Longpoke 2009-09-14 14:42:08 UTC
Found the problem, there are a bunch of NULL pointer dereferences in gdk/x11/gdkscreen-x11.c:

gint
gdk_screen_get_monitor_width_mm	(GdkScreen *screen,
				 gint       monitor_num)
{
  return get_monitor (screen, monitor_num)->width_mm;
}
Comment 2 Romain Perier (RETIRED) gentoo-dev 2009-09-15 18:10:19 UTC
(bug:13764): Gdk-CRITICAL **: get_monitor: assertion `monitor_num >= 0' failed

So if you give -1 it's totally normal, the assertion is false because -1 < 0.
however the segfault it's not normal...

Could you paste a full backtrace, to confirm what you said ?
Comment 3 Romain Perier (RETIRED) gentoo-dev 2009-09-15 18:11:18 UTC
see http://www.gentoo.org/proj/en/qa/backtraces.xml about the backtrace
Comment 4 Mart Raudsepp gentoo-dev 2009-09-28 15:44:36 UTC
I suggest upgrading to gtk+-2.16.x first and trying with that. 2.16 is stable by now and I believe saw some multi-head and other monitor related fixes, probably including usage of RANDR1.3 and some such.
Comment 5 Pacho Ramos gentoo-dev 2010-03-13 10:33:11 UTC
Please provide requested info. Thanks