x11 icon indicating copy to clipboard operation
x11 copied to clipboard

Failing to read XAuthority file on Ubuntu 22.04

Open nhrdl opened this issue 1 year ago • 3 comments

I tried the default hello world example and it fails to read the XAuthority file on Ubuntu 22.04. Following code snippet seems to be working in reading the file and it does show window. Following code is based on https://stackoverflow.com/a/74840795

    public static Optional<XAuthority> read(DataInput in) {
        try {
            int family = in.readUnsignedShort();
            int addLength = in.readUnsignedShort();
            List<Byte> host = readBytes(in, addLength);
            int displayNoLength = in.readUnsignedShort(), displayNumber = 0;

            if (displayNoLength != 0) {
                List<Byte> displayNo = readBytes(in, displayNoLength);
            }
            int nameLength = in.readUnsignedShort();
            List<Byte> authName = readBytes(in, nameLength);
            int dataLength = in.readUnsignedShort();
            List<Byte> authData = readBytes(in, dataLength);
            XAuthority auth = new XAuthority(Family.getByCode(family), host, displayNumber, authName, authData);
            return Optional.of(auth);

        } catch (Exception e) {
            // TODO Auto-generated catch block
            throw new RuntimeException(e);
        }
    }

Since XClient constructor was private, I ended up using reflection to call the constructor using something like following

X11Connection connect = X11Connection.connect(false, new DisplayName(":1"), auth);
Constructor<X11Client> accessibleConstructor = ReflectionUtils.accessibleConstructor(X11Client.class,
        X11Connection.class);
try (X11Client x11Client = accessibleConstructor.newInstance(connect)) { ....

nhrdl avatar Dec 24 '24 21:12 nhrdl

Is this with version 0.19.0? It could be due to the little endian changes and the file being big endian.

moaxcp avatar Dec 25 '24 20:12 moaxcp

Yes, version 0.19.0.

I tried with enedian settings both true and false. Result is still same. I get folowing exception

  Exception in thread "main" java.lang.NumberFormatException: For input string: ""
	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
	at java.base/java.lang.Integer.parseInt(Integer.java:672)
	at java.base/java.lang.Integer.parseInt(Integer.java:778)
	at com.github.moaxcp.x11.protocol.XAuthority.read(XAuthority.java:101)
	at com.github.moaxcp.x11.protocol.XAuthority.getAuthorities(XAuthority.java:161)
	at com.github.moaxcp.x11.x11client.X11Connection.connect(X11Connection.java:148)
	at com.github.moaxcp.x11.x11client.X11Client.connect(X11Client.java:74)
	at com.paymentus.bfs.aggregation.x11.X11Driver.main(X11Driver.java:202)

nhrdl avatar Dec 26 '24 16:12 nhrdl

I release 0.20.0 with a fix that should help.

moaxcp avatar Dec 27 '24 02:12 moaxcp