Skip to content

Fix panic during device enumeration on duplicate interface descriptors - #140

Open
BryanDClark wants to merge 1 commit into
google:masterfrom
BryanDClark:fix-duplicate-interface-panic
Open

BryanDClark wants to merge 1 commit into
google:masterfrom
BryanDClark:fix-duplicate-interface-panic

Conversation

@BryanDClark

Copy link
Copy Markdown
Contributor

Summary

When a USB device reports non-contiguous duplicate interface descriptors with the same (bInterfaceNumber, bAlternateSetting) pair (for example: interface 0/alt 0, interface 1/alt 0, interface 0/alt 0), libusb emits separate libusb_interface entries. Previously, getDeviceDesc() deduplicated alternate settings across the config with hasIntf and skipped every duplicate entry without checking whether descs was empty, causing an out-of-range panic on descs[0].Number during Context.OpenDevices().

Changes

  • Extracted interface deduplication into buildInterfaceDescs in libusb.go and added if len(descs) == 0 { continue } so interface entries whose alternate settings were all duplicates are skipped instead of panicking.
  • Tightened the iface.num_altsetting <= 0 guard in getDeviceDesc().
  • Added TestBuildInterfaceDescs in device_test.go covering normal, non-contiguous duplicate, partial duplicate, intra-interface duplicate, empty, and nil interface descriptor inputs.

Testing

  • Ran gofmt, go build ./..., go test -v ./..., go test -v -race -run TestBuildInterfaceDescs ., and ./.github/test-coverage.sh.

…settings

When a USB device presents non-contiguous duplicate interface descriptors with
the same (bInterfaceNumber, bAlternateSetting) pair, libusb emits separate
libusb_interface entries and getDeviceDesc() skips all duplicate alternate
settings without checking whether descs is empty, causing an out-of-range panic
on descs[0].Number during device enumeration.

Extract interface deduplication into buildInterfaceDescs and skip appending an
InterfaceDesc whenever all alternate settings for an interface entry were
filtered out as duplicates.

**Verification Details:** Ran go test -v ./..., go test -v -race -run TestBuildInterfaceDescs ., gofmt, and .github/test-coverage.sh locally; all tests pass including new regression tests for non-contiguous duplicate interface descriptors.
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

Successfully merging this pull request may close these issues.

1 participant