Skip to content

Overflow while getting descriptors #3

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

Closed
ecki opened this issue Dec 28, 2014 · 4 comments · May be fixed by #18
Closed

Overflow while getting descriptors #3

ecki opened this issue Dec 28, 2014 · 4 comments · May be fixed by #18

Comments

@ecki
Copy link

ecki commented Dec 28, 2014

While running usb4java-javax-example DumpNames I get an overflow error while reading manufacturer and product name.

The problems happens in LibUsb.getDescriptor() called by AbstractDevice#getLanguages(), but when I ignore this overflow (using language 0) a similiar error happens on AbstractDevice#getUsbStringDescriptor().

I tried to increase the ByteBuffer allocation, but this does not help.

C:\ws\github\usb4java-javax-examples>java -cp target\usb4java-javax-examples-1.0.0-SNAPSHOT.jar;c:\users\eckenfel\.m2\repository\org\usb4java\libusb4java\1.2.0\libusb4java-1.2.0-windows-x86_64.jar;c:\Users\eckenfel\.m2\repository\org\usb4java\usb4java-javax\1.2.1-SNAPSHOT\usb4java-javax-1.2.1-SNAPSHOT.jar;c:\users\eckenfel\.m2\repository\javax\usb\usb-api\1.0.2\usb-api-1.0.2.jar;C:\users\eckenfel\.m2\repository\org\usb4java\usb4java\1.2.0\usb4java-1.2.0.jar;C:\users\eckenfel\.m2\repository\org\apache\commons\commons-lang3\3.1\commons-lang3-3.1.jar org.usb4java.javax.examples.DumpNames
USB Service Implementation: usb4java
Implementation version: 1.2.0
Service API version: 1.0.2

Ignoring problematic device: Bus 001 Device 005: ID 1050:0120
javax.usb.UsbPlatformException: USB error 8: Unable to get string descriptor languages: Overflow
    at org.usb4java.javax.ExceptionUtils.createPlatformException(ExceptionUtils.java:39)
    at org.usb4java.javax.AbstractDevice.getLanguages(AbstractDevice.java:544)
    at org.usb4java.javax.AbstractDevice.getUsbStringDescriptor(AbstractDevice.java:507)
    at org.usb4java.javax.AbstractDevice.getString(AbstractDevice.java:526)
    at org.usb4java.javax.examples.DumpNames.dumpName(DumpNames.java:53)
    at org.usb4java.javax.examples.DumpNames.processDevice(DumpNames.java:87)
    at org.usb4java.javax.examples.DumpNames.processDevice(DumpNames.java:75)
    at org.usb4java.javax.examples.DumpNames.processDevice(DumpNames.java:75)
    at org.usb4java.javax.examples.DumpNames.main(DumpNames.java:122)

I can work around this with ignoring the Overflow:

if (result == LibUsb.ERROR_OVERFLOW) return new short[0];

Ignoring problematic device: Bus 001 Device 005: ID 1050:0120
javax.usb.UsbPlatformException: USB error 8: Unable to get string descriptor 1 from device Bus 001 Device 005: ID 1050:0120: Overflow
    at org.usb4java.javax.ExceptionUtils.createPlatformException(ExceptionUtils.java:39)
    at org.usb4java.javax.AbstractDevice.getUsbStringDescriptor(AbstractDevice.java:515)
    at org.usb4java.javax.AbstractDevice.getString(AbstractDevice.java:526)
    at org.usb4java.javax.examples.DumpNames.dumpName(DumpNames.java:53)
    at org.usb4java.javax.examples.DumpNames.processDevice(DumpNames.java:87)
    at org.usb4java.javax.examples.DumpNames.processDevice(DumpNames.java:75)
    at org.usb4java.javax.examples.DumpNames.processDevice(DumpNames.java:75)
    at org.usb4java.javax.examples.DumpNames.main(DumpNames.java:122)

NB: using DumpDevices if usb4java-examples works with the device (it is using getStringDescriptorAscii). It looks like:

Device 001/005
Connected to port: 2
Parent: 001/002
Speed: Full
Device Descriptor:
  bLength                 18
  bDescriptorType          1
  bcdUSB                2.00
  bDeviceClass             0 Per Interface
  bDeviceSubClass          0
  bDeviceProtocol          0
  bMaxPacketSize0         64
  idVendor            0x1050
  idProduct           0x0120
  bcdDevice             3.32
  iManufacturer            1 Yubico
  iProduct                 2 Security Key by Yubico
  iSerial                  0
  bNumConfigurations       1
...

This is on Win7 (german, 64bit) with the Yubico security-key (HID) and 64bit Java7U72.

@qiukeren
Copy link

qiukeren commented Sep 2, 2017

+1 for this issue.
jdk8 with win10

    private short[] getLanguages() throws UsbException
    {
        final DeviceHandle handle = open();
        final ByteBuffer buffer = ByteBuffer.allocateDirect(256);
        final int result = LibUsb.getDescriptor(handle, LibUsb.DT_STRING,
            (byte) 0, buffer);
        if (result < 0)
        {
            throw ExceptionUtils.createPlatformException(
                "Unable to get string descriptor languages", result);
        }
        if (result < 2)
            throw new UsbException("Received illegal descriptor length: "
                + result);
        final short[] languages = new short[(result - 2) / 2];
        if (languages.length == 0) return languages;
        buffer.position(2);
        buffer.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(languages);
        return languages;
    }

here throws this exception

@kayahr
Copy link
Member

kayahr commented Oct 21, 2018

usb4java 1.3.0 was released today which now uses libusb 1.0.22 which may have fixed this issue. Please try again with this new version and give feedback here if the exact same problem still occurs. If it still doesn't work but it is not the exact same result then please open a new issue.

@kayahr kayahr closed this as completed Oct 21, 2018
@gegomu
Copy link

gegomu commented Mar 27, 2019

it still happends

@scubajorgen
Copy link

Usb4java 1.3.0 solved the issue that the library sometimes doesn't work under Windows 10 (for my TomTom Watch project).
I encountered the Overflow issue described here as well. What did work for me was to replace the HidUsb driver by the WinUsb driver using the Zadig driver tool: http://zadig.akeo.ie.
Refer to my blog page, the Installation section

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