vpelletier / python-libusb1

Python ctype-based wrapper around libusb1
GNU Lesser General Public License v2.1
168 stars 65 forks source link

ValueError: Invalid string descriptor #25

Closed mangodan2003 closed 7 years ago

mangodan2003 commented 7 years ago

It seems usb1 is expecting the full string descriptor whereas libusb seems to returning only the string part.

If I hack the code at or around line 1350 to not check for the DT_STRING type and return the full result instead of just a subset it works as expected.

    manufacturer_string = device.getManufacturer()
  File "/usr/local/lib/python3.4/dist-packages/usb1/__init__.py", line 1961, in getManufacturer
    self.device_descriptor.iManufacturer)
  File "/usr/local/lib/python3.4/dist-packages/usb1/__init__.py", line 1953, in _getASCIIStringDescriptor
    return self.open().getASCIIStringDescriptor(descriptor)
  File "/usr/local/lib/python3.4/dist-packages/usb1/__init__.py", line 1351, in getASCIIStringDescriptor
    raise ValueError('Invalid string descriptor')
ValueError: Invalid string descriptor
        #if received < 2:# or descriptor_string[1] != DT_STRING:
        #    print('received : {}, descriptor_string[1] : {}'.format(received,descriptor_string[1]))
        #    raise ValueError('Invalid string descriptor')
        #return descriptor_string[2:min(
        #    received,
        #    descriptor_string[0],
        #)].decode('ASCII', errors=errors)
        return descriptor_string.decode('ASCII', errors=errors)
vpelletier commented 7 years ago

Thanks for the report.

Indeed, getStringDescriptor returns the whole descriptor, but getASCIIStringDescriptor only returns its payload.

This is now fixed in newly-released 1.6.2 .