Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception ArrayIndexOutOfBoundsException during exporting a dbus object #265

Open
dkokorev opened this issue Aug 23, 2024 · 3 comments
Open

Comments

@dkokorev
Copy link

dkokorev commented Aug 23, 2024

Hi, using dbus-java 3.2.0 I got an exception:

java.lang.ArrayIndexOutOfBoundsException: Index 10 out of bounds for length 10
	at org.freedesktop.dbus.Marshalling.recursiveGetDBusType(Marshalling.java:157)
	at org.freedesktop.dbus.Marshalling.recursiveGetDBusType(Marshalling.java:288)
	at org.freedesktop.dbus.Marshalling.recursiveGetDBusType(Marshalling.java:264)
	at org.freedesktop.dbus.Marshalling.recursiveGetDBusType(Marshalling.java:288)
	at org.freedesktop.dbus.Marshalling.recursiveGetDBusType(Marshalling.java:264)
	at org.freedesktop.dbus.Marshalling.recursiveGetDBusType(Marshalling.java:288)
	at org.freedesktop.dbus.Marshalling.recursiveGetDBusType(Marshalling.java:264)
	at org.freedesktop.dbus.Marshalling.recursiveGetDBusType(Marshalling.java:288)
	at org.freedesktop.dbus.Marshalling.recursiveGetDBusType(Marshalling.java:264)
	at org.freedesktop.dbus.Marshalling.recursiveGetDBusType(Marshalling.java:288)
	at org.freedesktop.dbus.Marshalling.recursiveGetDBusType(Marshalling.java:288)
	at org.freedesktop.dbus.Marshalling.getDBusType(Marshalling.java:148)
	at org.freedesktop.dbus.Marshalling.getDBusType(Marshalling.java:133)
	at org.freedesktop.dbus.messages.ExportedObject.getExportedMethods(ExportedObject.java:186)
	at org.freedesktop.dbus.messages.ExportedObject.getExportedMethods(ExportedObject.java:198)
	at org.freedesktop.dbus.messages.ExportedObject.<init>(ExportedObject.java:51)
	at org.freedesktop.dbus.connections.AbstractConnection.exportObject(AbstractConnection.java:269)

It's because of the problem in org.freedesktop.dbus.Marshalling class (the same code up to the latest version of dbus-java):

...
private static String[] recursiveGetDBusType(StringBuffer[] _out, Type _dataType, boolean _basic, int _level) throws DBusException {
        if (_out.length <= _level) {
            StringBuffer[] newout = new StringBuffer[_out.length];
            System.arraycopy(_out, 0, newout, 0, _out.length);
            _out = newout;
        }
...

My solution is something like this:

-            StringBuffer[] newout = new StringBuffer[_out.length];
+            StringBuffer[] newout = new StringBuffer[_level + 10];
@hypfvieh
Copy link
Owner

When does this happen? Can you provide a sample to reproduce this?
Changing code with some random numbers may not be the ultimate solution when the cause of the error is unknown.

@dkokorev
Copy link
Author

dkokorev commented Aug 23, 2024

When does this happen? Can you provide a sample to reproduce this?

This happens when a dbus struct contains more than 10 levels of nesting.

Changing code with some random numbers may not be the ultimate solution when the cause of the error is unknown.

For simplicity I just used the initial allocation size from here:

public static String[] getDBusType(Type _dataType, boolean _basic) throws DBusException {
        return recursiveGetDBusType(new StringBuffer[10], _dataType, _basic, 0);
}

hypfvieh added a commit that referenced this issue Aug 23, 2024
@hypfvieh
Copy link
Owner

Will be fixed in next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants