Skip to content

Commit

Permalink
Handle descriptors that are longer than defined in the specification.…
Browse files Browse the repository at this point in the history
… Follow specification guidelines for doing so.
  • Loading branch information
x0rloser committed Sep 12, 2024
1 parent efc0c26 commit a682a05
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/usb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,11 +769,14 @@ impl Iterator for DescriptorIterator<'_> {
let desc_length = remaining_bytes[0] as usize;
let desc_type = DescriptorType::from(remaining_bytes[1]);
self.offset += desc_length;
// The expected length is the minimum length, but sometimes the
// descriptors have extra padding/garbage data at the end.
// Handle this by trimming off the extra data.
if let Some(expected) = desc_type.expected_length() {
if desc_length != expected {
if desc_length < expected {
continue
}
let bytes = &remaining_bytes[0 .. desc_length];
let bytes = &remaining_bytes[0 .. expected];
return Some(match desc_type {
DescriptorType::Device =>
Descriptor::Device(
Expand Down

0 comments on commit a682a05

Please sign in to comment.