NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

xsrc/59952: xsetwallpaper: server/client endian mismatch



>Number:         59952
>Category:       xsrc
>Synopsis:       xsetwallpaper: server/client endian mismatch
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    xsrc-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jan 31 02:30:00 +0000 2026
>Originator:     adrian chadd
>Release:        11.99.4
>Organization:
>Environment:
sgimips-r4000$ uname -a
NetBSD sgimips-r4000.home.cacheboy.io 11.99.4 NetBSD 11.99.4 (GENERIC32_IP2x) #0: Mon Jan 12 21:48:13 UTC 2026  mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/sgimips/compile/GENERIC32_IP2x sgimips

>Description:
xsetwallpaper assumes the image byte order was decoded into host byte order. however if you run xsetwallpaper on mismatching endian computers - eg amd64 (le) client, sgimips (be) server, then things are corrupted.
>How-To-Repeat:
Do the above: run xsetwallpaper on a different endian client to server.
>Fix:
I did a quick diff that just sets image->byte_order to host endian order so the library/server knows what to do with it.

The alternative solution is to not re-swizzle the endian-ness of the image data and leave it as little-endian.

===

diff --git a/src/xsetwallpaper.c b/src/xsetwallpaper.c
index 8b20050..335acea 100644
--- a/src/xsetwallpaper.c
+++ b/src/xsetwallpaper.c
@@ -104,6 +104,8 @@ main(int argc, char *argv[])
                data[i + 2] = p;
        }
 
+       /* At this point it's little endian regardless of host type. */
+
 #if _BYTE_ORDER == _BIG_ENDIAN
        for (i = 0; i < imagew * imageh * 4; i += 4) {
                uint32_t *p = (uint32_t *)&data[i];
@@ -111,6 +113,8 @@ main(int argc, char *argv[])
        }
 #endif
 
+       /* It is now in host endian */
+
 #ifdef DEBUG
        printf("%s: %dx%d %dbpp\n", argv[0], imagew, imageh, imagebpp * 8);
 #endif
@@ -168,7 +172,17 @@ main(int argc, char *argv[])
                errx(EXIT_FAILURE, "XCreateImage failed");
        }
        XInitImage(image);
-       image->byte_order = byte_order;
+
+       /*
+        * Set the image byte order.  Since the above code has converted it
+        * into host endian this will need to be communicated to the display
+        * server so it can re-swizzle if needed.
+        */
+#if _BYTE_ORDER == _BIG_ENDIAN
+       image->byte_order = MSBFirst;
+#else
+       image->byte_order = LSBFirst;
+#endif
 
        /* Create a graphics context for our new pixmap */
        gc = XCreateGC(display, window, 0, NULL);



Home | Main Index | Thread Index | Old Index