Subject: Bug#410: Segfault of _X11TransWritev in libNX_X11.so.6 with libQtGui

From: Sven Willenberger <[email-masked]>
Date: Thu, 23 Jan 2014 21:39:19 -0500

Package: nx-libs (nx-x11)
Version: 3.5.0.22

Server (host)OS: Linux 3.12.8 (ArchLinux) x86_64
Client OS: Windows 8 (version 4.0.1.2 QT 4.8.5)

When using python apps with QT (either PyQT or PySide), any interaction
with the resulting window (when connected from windows to linux) causes
the program to crash. Partial stack trace:

#0  0x00007fffed78acb0 in _X11TransWritev () from /usr/lib/nx/X11/libNX_X11.so.6
#1  0x00007fffed76eb8e in _XSend () from /usr/lib/nx/X11/libNX_X11.so.6
#2  0x00007fffed763e69 in XQueryExtension () from /usr/lib/nx/X11/libNX_X11.so.6
#3  0x00007fffed759af2 in XInitExtension () from /usr/lib/nx/X11/libNX_X11.so.6
#4  0x00007fffeda3d7bb in XextAddDisplay () from /usr/lib/nx/X11/libNX_Xext.so.6
#5  0x00007fffedc4cee1 in XPanoramiXQueryExtension () from /usr/lib/nx/X11/Xinerama/libXinerama.so.1
#6  0x00007ffff0e01e3e in ?? () from /usr/lib/python3.3/site-packages/PySide-1.2.1-py3.3.egg/PySide/libQtGui.so.4
#7  0x00007ffff0e01f42 in QDesktopWidget::QDesktopWidget() () from /usr/lib/python3.3/site-packages/PySide-1.2.1-py3.3.egg/PySide/libQtGui.so.4

This just happened with the Jan 4 update to nx-libs (et al).

For comparison, using a basic ssh connection with X-forwarding and
starting an xterm session and running the same python programs succeeds.

-- 
Sven Willenberger
United Pay Systems International
http://www.upsicorp.com

---

From: Mike Gabriel <[email-masked]>
Date: Wed, 11 Jun 2014 21:33:58 +0000

HI Sven,

On  Fr 24 Jan 2014 03:39:19 CET, Sven Willenberger wrote:

> #5  0x00007fffedc4cee1 in XPanoramiXQueryExtension () from  
> /usr/lib/nx/X11/Xinerama/libXinerama.so.1
> #6  0x00007ffff0e01e3e in ?? () from  
> /usr/lib/python3.3/site-packages/PySide-1.2.1-py3.3.egg/PySide/libQtGui.so.4
> #7  0x00007ffff0e01f42 in QDesktopWidget::QDesktopWidget() () from  
> /usr/lib/python3.3/site-packages/PySide-1.2.1-py3.3.egg/PySide/libQtGui.so.4
>

sorry for responding soooo late...

Today, I have been in NX code for the whole day and I wonder, if I can  
do something for you to get the above issue fixed.

I tested the above with this python snippet:

"""
#!/usr/bin/python

# simple.py

import sys
from PyQt4 import QtGui

app = QtGui.QApplication(sys.argv)

widget = QtGui.QWidget()
widget.resize(250, 150)
widget.setWindowTitle('simple')
widget.show()

sys.exit(app.exec_())
"""

and I don't bump into any problems as described above.

Can you please:

   1. get latest x2goagent/nxagent/libnx-x11 from our nightly builds[1]
   2. re-test the above
   3. if you get the same error, send me the python code that triggers
      the bug

Greets,
Mike

PS: please wait for the current build of nx-libs to finish [2]

[1] http://wiki.x2go.org/doku.php/wiki:development:nightly-builds
[2] https://jenkins.x2go.org:8443/view/NX/

-- 

DAS-NETZWERKTEAM
mike gabriel, herweg 7, 24357 fleckeby
fon: +49 (1520) 1976 148

GnuPG Key ID 0x25771B31
mail: [email-masked], http://das-netzwerkteam.de

freeBusy:
https://mail.das-netzwerkteam.de/freebusy/m.gabriel%40das-netzwerkteam.de.xfb

---

From: Mike Gabriel <[email-masked]>
Date: Thu, 12 Jun 2014 22:06:05 +0000

Hi Sven,

re-Cc:-ing bug #410...

On  Do 12 Jun 2014 21:48:42 CEST, Sven Willenberger wrote:

> On Wed, 11 Jun 2014 21:33:58 +0000
> Mike Gabriel <[email-masked]> wrote:
>
>> HI Sven,
>>
>> > When using python apps with QT (either PyQT or PySide), any
>> > interaction with the resulting window (when connected from windows
>> > to linux) causes the program to crash. Partial stack trace:
>> >
>> > #1  0x00007fffed76eb8e in _XSend ()
>> > from /usr/lib/nx/X11/libNX_X11.so.6 #2  0x00007fffed763e69 in
>> > XQueryExtension () from /usr/lib/nx/X11/libNX_X11.so.6
>> Today, I have been in NX code for the whole day and I wonder, if I
>> can do something for you to get the above issue fixed.
>>
>>    1. get latest x2goagent/nxagent/libnx-x11 from our nightly
>> builds[1] 2. re-test the above
> As I am on Archlinux, I need to apply patches from the debian/patches
> directory from the git pull. Besides the Pgn.cpp patch (for libpng),
> what other patches need to be applied to make the git behave like the
> nx-libs-3.5.0.xx-full.tar.gz releases? (for example to create a master
> Makefile).

nx-libs/debian/roll-tarball.sh is your friend...

But Clemens already helped out on IRC I just saw...

Mike
-- 

DAS-NETZWERKTEAM

GnuPG Key ID 0x25771B31

freeBusy:

---

From: Sven Willenberger <[email-masked]>
Date: Thu, 26 Jun 2014 16:39:24 -0400

So this goes into tracker:

I have isolated the problem to the following change in the nx-libs
Makefile between 3.5.0.21 and 3.5.0.22, which persists through HEAD:

--- nx-libs-3.5.0.21/Makefile   2014-06-14 12:45:27.000000000 -0400
+++ nx-libs-HEAD/Makefile       2014-06-12 16:31:48.000000000 -0400
@@ -3,6 +3,7 @@
 INSTALL_DIR=install -d -m 755
 INSTALL_FILE=install -m 644
 INSTALL_PROGRAM=install -m 755
+INSTALL_SYMLINK=ln -s -f
 COPY_SYMLINK=cp -a
 RM_FILE=rm -f
 RM_DIR=rmdir -p --ignore-fail-on-non-empty
@@ -114,6 +115,13 @@
                                "$$(string_rep "$$dirname" nx-X11/.build-exports/include "$(DESTDIR)$(PREFIX)/include/nx")"/ || true; \
            done; \
 
+       # Provide means for Xinerama support in NX/X2Go sessions. This
+       # This also requires two post-install symlinks:
+       # (DESTDIR)$(NXLIBDIR)/X11/Xinerama/libNX_X11.so.6 -> /usr/<libdir>/libX11.so.6
+       # (DESTDIR)$(NXLIBDIR)/X11/Xinerama/libNX_Xext.so.6 -> /usr/<libdir>/libXext.so.6
+       $(INSTALL_DIR) $(DESTDIR)$(NXLIBDIR)/X11/Xinerama
+       $(INSTALL_SYMLINK) ../libNX_Xinerama.so.1 $(DESTDIR)$(NXLIBDIR)/X11/Xinerama/libXinerama.so.1
+
        $(INSTALL_DIR) $(DESTDIR)$(PREFIX)/include/nx/X11/bitmaps
        $(INSTALL_FILE) nx-X11/.build-exports/include/X11/bitmaps/* \
                        $(DESTDIR)$(PREFIX)/include/nx/X11/bitmaps/

Commenting out the Xinerama lines and rebuilding results in a clean run
of my (and your) python scripts as well as VLC player.

I have attached a diff (excepting whitespace differences (diff -ub) of
my system's Xinerama.c (xorg's libXinerama 1.1.3) and the one provided
in x2go's source (based on XFree86).

--- /data/Downloads/ABS/libxinerama/libXinerama-1.1.3/src/Xinerama.c	2013-05-30 20:28:02.000000000 -0400
+++ Xinerama.c	2014-06-14 11:29:40.837433407 -0400
@@ -1,3 +1,4 @@
+/* $Xorg: XPanoramiX.c,v 1.4 2000/08/17 19:45:51 cpqbld Exp $ */
 /*****************************************************************
 Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
 Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -22,11 +23,10 @@
 dealings in this Software without prior written authorization from Digital
 Equipment Corporation.
 ******************************************************************/
+/* $XFree86: xc/lib/Xinerama/Xinerama.c,v 1.2 2001/07/23 17:20:28 dawes Exp $ */
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
+#define NEED_EVENTS
+#define NEED_REPLIES
 #include <X11/Xlibint.h>
 #include <X11/Xutil.h>
 #include <X11/extensions/Xext.h>
@@ -35,31 +35,17 @@
 #include <X11/extensions/panoramiXproto.h>
 #include <X11/extensions/Xinerama.h>
 
-#ifndef HAVE__XEATDATAWORDS
-#include <X11/Xmd.h>  /* for LONG64 on 64-bit platforms */
-#include <limits.h>
-
-static inline void _XEatDataWords(Display *dpy, unsigned long n)
-{
-# ifndef LONG64
-    if (n >= (ULONG_MAX >> 2))
-        _XIOError(dpy);
-# endif
-    _XEatData (dpy, n << 2);
-}
-#endif
 
 static XExtensionInfo _panoramiX_ext_info_data;
 static XExtensionInfo *panoramiX_ext_info = &_panoramiX_ext_info_data;
-static const char *panoramiX_extension_name = PANORAMIX_PROTOCOL_NAME;
+static /* const */ char *panoramiX_extension_name = PANORAMIX_PROTOCOL_NAME;
 
 #define PanoramiXCheckExtension(dpy,i,val) \
   XextCheckExtension (dpy, i, panoramiX_extension_name, val)
 #define PanoramiXSimpleCheckExtension(dpy,i) \
   XextSimpleCheckExtension (dpy, i, panoramiX_extension_name)
 
-static int close_display(Display *dpy, XExtCodes *codes);
-
+static int close_display();
 static /* const */ XExtensionHooks panoramiX_extension_hooks = {
     NULL,				/* create_gc */
     NULL,				/* copy_gc */
@@ -91,15 +77,15 @@
 
 Bool XPanoramiXQueryExtension (
     Display *dpy,
-    int *event_base_return,
-    int *error_base_return
+    int *event_basep,
+    int *error_basep
 )
 {
     XExtDisplayInfo *info = find_display (dpy);
 
     if (XextHasExtension(info)) {
-	*event_base_return = info->codes->first_event;
-	*error_base_return = info->codes->first_error;
+	*event_basep = info->codes->first_event;
+	*error_basep = info->codes->first_error;
 	return True;
     } else {
 	return False;
@@ -109,8 +95,8 @@
 
 Status XPanoramiXQueryVersion(
     Display *dpy,
-    int     *major_version_return,
-    int     *minor_version_return
+    int	    *major_versionp, 
+    int *minor_versionp
 )
 {
     XExtDisplayInfo *info = find_display (dpy);
@@ -130,8 +116,8 @@
 	SyncHandle ();
 	return 0;
     }
-    *major_version_return = rep.majorVersion;
-    *minor_version_return = rep.minorVersion;
+    *major_versionp = rep.majorVersion;
+    *minor_versionp = rep.minorVersion;
     UnlockDisplay (dpy);
     SyncHandle ();
     return 1;
@@ -241,11 +227,11 @@
 
 Bool XineramaQueryExtension (
    Display *dpy,
-   int     *event_base_return,
-   int     *error_base_return
+   int     *event_base,
+   int     *error_base
 )
 {
-   return XPanoramiXQueryExtension(dpy, event_base_return, error_base_return);
+   return XPanoramiXQueryExtension(dpy, event_base, error_base);
 }
 
 Status XineramaQueryVersion(
@@ -280,6 +266,8 @@
     return rep.state;
 }
 
+#include <stdio.h>
+
 XineramaScreenInfo *
 XineramaQueryScreens(
    Display *dpy,
@@ -291,7 +279,7 @@
     xXineramaQueryScreensReq	*req;
     XineramaScreenInfo		*scrnInfo = NULL;
 
-    PanoramiXCheckExtension (dpy, info, NULL);
+    PanoramiXCheckExtension (dpy, info, 0);
 
     LockDisplay (dpy);
     GetReq (XineramaQueryScreens, req);
@@ -303,26 +291,13 @@
 	return NULL;
     }
 
-    /*
-     * rep.number is a CARD32 so could be as large as 2^32
-     * The X11 protocol limits the total screen size to 64k x 64k,
-     * and no screen can be smaller than a pixel.  While technically
-     * that means we could theoretically reach 2^32 screens, and that's
-     * not even taking overlap into account, Xorg is currently limited
-     * to 16 screens, and few known servers have a much higher limit,
-     * so 1024 seems more than enough to prevent both integer overflow
-     * and insane X server responses causing massive memory allocation.
-     */
-    if ((rep.number > 0) && (rep.number <= 1024))
-	scrnInfo = Xmalloc(sizeof(XineramaScreenInfo) * rep.number);
-    if (scrnInfo != NULL) {
-	int i;
-
-	for (i = 0; i < rep.number; i++) {
+    if(rep.number) {
+	if((scrnInfo = Xmalloc(sizeof(XineramaScreenInfo) * rep.number))) {
 	    xXineramaScreenInfo scratch;
+	    int i;
 
+	    for(i = 0; i < rep.number; i++) {
 	    _XRead(dpy, (char*)(&scratch), sz_XineramaScreenInfo);
-
 	    scrnInfo[i].screen_number = i;
 	    scrnInfo[i].x_org	= scratch.x_org;
 	    scrnInfo[i].y_org	= scratch.y_org;
@@ -331,12 +306,14 @@
 	}
 
 	*number = rep.number;
-    } else {
-	_XEatDataWords(dpy, rep.length);
-	*number = 0;
+	} else
+	    _XEatData(dpy, rep.length << 2);
     }
 
     UnlockDisplay (dpy);
     SyncHandle ();
     return scrnInfo;
 }
+
+
+

---

From: Mike Gabriel <[email-masked]>
Date: Mon, 30 Jun 2014 11:22:07 +0000

Hi Sven,

On  Do 26 Jun 2014 22:39:24 CEST, Sven Willenberger wrote:

>                                 "$$(string_rep "$$dirname"  
> nx-X11/.build-exports/include "$(DESTDIR)$(PREFIX)/include/nx")"/ ||  
> true; \
>             done; \
>
> +       $(INSTALL_SYMLINK) ../libNX_Xinerama.so.1  
> $(DESTDIR)$(NXLIBDIR)/X11/Xinerama/libXinerama.so.1
> +

I really cannot reproduce the above issue on Debian.

But I have a suspicion...

Can you please check on Archlinux if you have the two other symlinks  
that are required for Xinerama to work?

""" (quoted from above...)
+       # Provide means for Xinerama support in NX/X2Go sessions. This
+       # This also requires two post-install symlinks:
+       # (DESTDIR)$(NXLIBDIR)/X11/Xinerama/libNX_X11.so.6 ->  
/usr/<libdir>/libX11.so.6
+       # (DESTDIR)$(NXLIBDIR)/X11/Xinerama/libNX_Xext.so.6 ->  
/usr/<libdir>/libXext.so.6
"""

If those are missing, please file a bug against the x2goserver package  
in Archlinux. The correct links have to be provided by the package  
maintainer (not by us upstream people).

If those links are missing: can you please create them and give  
feedback if the problem still occurs for you?

And...

Is my assumption correct that this bug only occurs if Xinerama has  
been enabled in the X2Go session's session profile (see profile  
manager window in X2Go Client).

Greets+Thanks!

Mike
-- 

DAS-NETZWERKTEAM

GnuPG Key ID 0x25771B31

freeBusy:

---

From: Sven Willenberger <[email-masked]>
Date: Mon, 30 Jun 2014 11:32:14 -0400

On Mon, 30 Jun 2014 11:22:07 +0000
Mike Gabriel <[email-masked]> wrote:

> If those are missing, please file a bug against the x2goserver
> package in Archlinux. The correct links have to be provided by the
> package maintainer (not by us upstream people).
> 

I went ahead and changed the PKGBUILD file (Archlinux's package
building spec file) to include the symlinks as you pointed out (and as
are contained as comments in the Makefile) and rebuilt the package. It
works!! (pyQt, PySide, vlc all work now). That was the fix that was
needed and will report this to the package maintainers.

Regarding your assumption, it is actually incorrect. I do not have
Xinerama checked as an option in my session profile (it is unchecked)
so that had no bearing on the issue rearing itself.

Thanks!!

---

From: Mike Gabriel <[email-masked]>
Date: Mon, 30 Jun 2014 20:02:58 +0000

close #410
close #113
close #467
thanks

Hi Sven,

> needed and will report this to the package maintainers.

Great that we could track this down...

@all: X2Go BTS issues #113, #410 and #467 have been identified as  
packaging issues on Archlinux. For further reference, see here:

https://bugs.archlinux.org/task/41037

Sven, thanks for your help and providing your distro-specific  
expertise on this...
Mike
-- 

DAS-NETZWERKTEAM

GnuPG Key ID 0x25771B31

freeBusy:

---

From: [email-masked] (X2Go Bug Tracking System)
Date: Mon, 30 Jun 2014 20:05:02 +0000

This is an automatic notification regarding your Bug report
which was filed against the nxagent package:

#410: Segfault of _X11TransWritev in libNX_X11.so.6 with libQtGui

It has been closed by Mike Gabriel <[email-masked]>.

Their explanation is attached below along with your original report.
If this explanation is unsatisfactory and you have not received a
better one in a separate message then please contact Mike Gabriel <[email-masked]> by
replying to this email.

-- 
X2Go Bug Tracking System
Contact [email-masked] with problems

Subject: Re: Bug#410: Segfault of _X11TransWritev in libNX_X11.so.6 with libQtGui
From: Mike Gabriel <[email-masked]>
To: Sven Willenberger <[email-masked]>
Cc: [email-masked], [email-masked]
Date: Mon, 30 Jun 2014 20:02:58 +0000

close #410
close #113
close #467
thanks

Hi Sven,

DAS-NETZWERKTEAM

GnuPG Key ID 0x25771B31

freeBusy:

Subject: Segfault of _X11TransWritev in libNX_X11.so.6 with libQtGui
From: Sven Willenberger <[email-masked]>
To: [email-masked]
Date: Thu, 23 Jan 2014 21:39:19 -0500