_open_vc_itf parsing error when vc->std.bNumEndpoints != 0#3532
_open_vc_itf parsing error when vc->std.bNumEndpoints != 0#3532YixingShen wants to merge 3 commits intohathach:masterfrom
Conversation
Standard Interface Descriptor (Video Control)
Video Control Header Descriptor
Video Control Camera Terminal Descriptor
Video Control Output Terminal Descriptor
Standard Endpoint Descriptor
Class-Specific VC Interrupt Endpoint Descriptor
Video Control Header Descriptor's wTotalLength
= Header Descriptor + Camera Terminal Descriptor + Output Terminal Descriptor
_end_of_control_descriptor is Output Terminal Descriptor End
the "end" should +7 for _find_desc searchig Standard Endpoint Descriptor
There was a problem hiding this comment.
Pull request overview
Fixes UVC VideoControl (VC) interface parsing when vc->std.bNumEndpoints != 0 by ensuring the endpoint descriptor is included in the search window derived from wTotalLength.
Changes:
- Extends the computed “end of VC descriptor” pointer so
_find_desc(..., TUSB_DESC_ENDPOINT)can find the notification endpoint descriptor.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/class/video/video_device.c
Outdated
|
|
||
| /* Update to point the end of the video control interface descriptor. */ | ||
| end = _end_of_control_descriptor(cur); | ||
| end = _end_of_control_descriptor(cur) + 7; |
There was a problem hiding this comment.
Extending end by a hard-coded 7 bytes inside _open_vc_itf() fixes the endpoint search, but the same endpoint lookup pattern in _close_vc_itf() still uses _end_of_control_descriptor() without extending the search range and will return end/assert when bNumEndpoints != 0. Consider introducing a helper that computes the true end of the VC interface including the notification endpoint descriptor(s) (only when bNumEndpoints is non-zero), and use it in both open/close so behavior stays consistent.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@claude review this |
|
Claude finished @hathach's task in 1m 35s —— View job Code Review
Bug AnalysisThe fix addresses a real bug. return ((uint8_t const*) desc) + vc->std.bLength + tu_le16toh(vc->ctl.wTotalLength);Per the UVC spec, Issues with the Current Fix1. Pointer arithmetic on // As submitted:
end = _end_of_control_descriptor(cur) + 7;
end = (uint8_t const *)_end_of_control_descriptor(cur) + sizeof(tusb_desc_endpoint_t);2. Magic number Use 3.
// _close_vc_itf() – still broken when bNumEndpoints != 0
void const *end = _end_of_control_descriptor(vc); // line 741
...
cur = _find_desc(cur, end, TUSB_DESC_ENDPOINT); // line 744
TU_ASSERT(cur < end); // will fire!With 4. Fragility of Extending static inline void const* _end_of_vc_descriptor(void const *desc)
{
tusb_desc_vc_itf_t const *vc = (tusb_desc_vc_itf_t const *)desc;
uint8_t const *end = (uint8_t const*)desc + vc->std.bLength
+ tu_le16toh(vc->ctl.wTotalLength);
if (vc->std.bNumEndpoints) {
end += sizeof(tusb_desc_endpoint_t); // standard EP descriptor
end += 5; // class-specific EP descriptor (fixed 5 bytes per UVC spec)
}
return end;
}This keeps both Summary
The core diagnosis is right, but the patch will not build as submitted and leaves |
The Hierarchy and Memory Layout
Standard Interface Descriptor (VC)
Video Control Header Descriptor: Contains wTotalLength.
Video Control Camera Terminal Descriptor
Video Control Output Terminal Descriptor
Standard Endpoint Descriptor: The physical interrupt pipe (Length = 7 bytes).
Class-Specific VC Interrupt Endpoint Descriptor: Additional endpoint metadata (Length = 5 bytes).
_end_of_control_descriptor is Output Terminal Descriptor End
the "end" should +7 for _find_desc searching Standard Endpoint Descriptor when vc->std.bNumEndpoints != 0