Skip to content

Exception ArrayIndexOutOfBoundsException during exporting a dbus object #265

Closed

Description

@dkokorev

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];

Activity

  1. hypfvieh commented on Aug 23, 2024

    @hypfvieh
    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.

  2. dkokorev commented on Aug 23, 2024

    @dkokorev
    Author

    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);
    }
    
  3. added a commit that references this issue on Aug 23, 2024
  4. hypfvieh commented on Aug 23, 2024

    @hypfvieh
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions