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

Example app crashed on Windows #15

Closed
fpagliughi opened this issue Feb 21, 2020 · 2 comments
Closed

Example app crashed on Windows #15

fpagliughi opened this issue Feb 21, 2020 · 2 comments

Comments

@fpagliughi
Copy link
Contributor

Tried running the list_devices example on Windows 7. It got the first four devices OK, then on the fifth one it crashed:

Bus 003 Device 005 ID 046d:c52f   12 Mbps
Device Descriptor:
  bcdUSB              2.00
  bDeviceClass        0x00
  bDeviceSubClass     0x00
  bDeviceProtocol     0x00
  bMaxPacketSize0        8
  idVendor          0x046d
  idProduct         0xc52f
  bcdDevice          30.00
thread 'main' panicked at 'index out of bounds: the len is 1 but the index is 1', C:\Temp\rusb\src\device_handle.rs:587:58
stack backtrace:
   0: std::sys_common::backtrace::_print::{{impl}}::fmt
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\/src\libstd\sys_common\backtrace.rs:61
   1: core::fmt::write
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\/src\libcore\fmt\mod.rs:1025
   2: std::io::Write::write_fmt<std::sys::windows::stdio::Stderr>
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\/src\libstd\io\mod.rs:1427
   3: std::panicking::default_hook::{{closure}}
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\/src\libstd\panicking.rs:193
   4: std::panicking::default_hook
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\/src\libstd\panicking.rs:212
   5: std::panicking::rust_panic_with_hook
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\/src\libstd\panicking.rs:471
   6: std::panicking::begin_panic_handler
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\/src\libstd\panicking.rs:375
   7: core::panicking::panic_fmt
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\/src\libcore\panicking.rs:84
   8: core::panicking::panic_bounds_check
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\/src\libcore\panicking.rs:62
   9: rusb::device_handle::{{impl}}::read_string_descriptor::{{closure}}<rusb::context::GlobalContext>
             at .\src\device_handle.rs:587
  10: core::ops::function::impls::{{impl}}::call_once<(slice<u8>*),closure-0>
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\src\libcore\ops\function.rs:285
  11: core::option::Option<slice<u8>*>::map<slice<u8>*,u16,mut closure-0*>
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\src\libcore\option.rs:450
  12: core::iter::adapters::{{impl}}::next<u16,core::iter::adapters::Skip<core::slice::Chunks<u8>>,closure-0>
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\src\libcore\iter\adapters\mod.rs:720
  13: alloc::vec::Vec<u16>::extend_desugared<u16,core::iter::adapters::Map<core::iter::adapters::Skip<core::slice::Chunks<u8>>, closure-0>>
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\src\liballoc\vec.rs:2118
  14: alloc::vec::{{impl}}::spec_extend<u16,core::iter::adapters::Map<core::iter::adapters::Skip<core::slice::Chunks<u8>>, closure-0>>
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\src\liballoc\vec.rs:2016
  15: alloc::vec::{{impl}}::from_iter<u16,core::iter::adapters::Map<core::iter::adapters::Skip<core::slice::Chunks<u8>>, closure-0>>
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\src\liballoc\vec.rs:2010
  16: alloc::vec::{{impl}}::from_iter<u16,core::iter::adapters::Map<core::iter::adapters::Skip<core::slice::Chunks<u8>>, closure-0>>
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\src\liballoc\vec.rs:1912
  17: core::iter::traits::iterator::Iterator::collect<core::iter::adapters::Map<core::iter::adapters::Skip<core::slice::Chunks<u8>>, closure-0>,alloc::vec::Vec<u16>>
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\src\libcore\iter\traits\iterator.rs:1495
  18: rusb::device_handle::DeviceHandle<rusb::context::GlobalContext>::read_string_descriptor<rusb::context::GlobalContext>
             at .\src\device_handle.rs:590
  19: rusb::device_handle::DeviceHandle<rusb::context::GlobalContext>::read_manufacturer_string<rusb::context::GlobalContext>
             at .\src\device_handle.rs:611
  20: list_devices::print_device::{{closure}}<rusb::context::GlobalContext>
             at .\examples\list_devices.rs:108
  21: core::option::Option<mut list_devices::UsbDevice<rusb::context::GlobalContext>*>::map_or<mut list_devices::UsbDevice<rusb::context::GlobalContext>*,alloc::string::String,closure-0>
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\src\libcore\option.rs:471
  22: list_devices::print_device<rusb::context::GlobalContext>
             at .\examples\list_devices.rs:105
  23: list_devices::list_devices
             at .\examples\list_devices.rs:54
  24: list_devices::main
             at .\examples\list_devices.rs:14
  25: std::rt::lang_start::{{closure}}<()>
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\src\libstd\rt.rs:67
  26: std::panicking::try::do_call<closure-0,i32>
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\/src\libstd\panicking.rs:292
  27: panic_unwind::__rust_maybe_catch_panic
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\/src\libpanic_unwind\lib.rs:78
  28: std::rt::lang_start_internal
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\/src\libstd\rt.rs:51
  29: std::rt::lang_start<()>
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\src\libstd\rt.rs:67
  30: main
  31: __scrt_common_main_seh
             at d:\agent\_work\3\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  32: BaseThreadInitThunk
  33: RtlUserThreadStart
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
@a1ien
Copy link
Owner

a1ien commented Feb 22, 2020

This is more like a broken device. Which returns the wrong string.
Try replace read_manufacturer_string call on line 107 to read_manufacturer_string_ascii

@fpagliughi
Copy link
Contributor Author

Ah, OK. But I think the library should not panic on a bad string descriptor. We should at least test that the length of the descriptor is an even number, greater than 2 before trying to parse the string.

For a string descriptor, should the number of bytes read also be the length in the descriptor (byte 0)? If so, we could verify that as well.

I will have a look and send a PR if I think I can fix it.

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