Repository navigation
Fix panic during device enumeration on duplicate interface descriptors - #140
Open
BryanDClark wants to merge 1 commit into
Open
BryanDClark wants to merge 1 commit into
BryanDClark wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 separatelibusb_interfaceentries. Previously,getDeviceDesc()deduplicated alternate settings across the config withhasIntfand skipped every duplicate entry without checking whetherdescswas empty, causing an out-of-range panic ondescs[0].NumberduringContext.OpenDevices().Changes
buildInterfaceDescsinlibusb.goand addedif len(descs) == 0 { continue }so interface entries whose alternate settings were all duplicates are skipped instead of panicking.iface.num_altsetting <= 0guard ingetDeviceDesc().TestBuildInterfaceDescsindevice_test.gocovering normal, non-contiguous duplicate, partial duplicate, intra-interface duplicate, empty, and nil interface descriptor inputs.Testing
gofmt,go build ./...,go test -v ./...,go test -v -race -run TestBuildInterfaceDescs ., and./.github/test-coverage.sh.