From 04887fa922365c77bf3502e49362f66144839caf Mon Sep 17 00:00:00 2001
From: John Thacker <johnthacker@gmail.com>
Date: Tue, 31 Mar 2026 11:19:57 +0000
Subject: [PATCH] USB HID: Skip items with a report size of zero

Items with a report size of zero don't advance the offset and
take up no room in the data, so there's nothing to display.
It can lead to a very long loop if the report count is extremely
long.

Items with a non zero report size advance the offset, so we'll
eventually throw an exception no matter the number of reported
items.

It's not clear from the USB HID spec if a report size of zero is
legal, but it doesn't make much sense.

Fix #21121

AI-Assisted: no


(cherry picked from commit 9ed3457896839c66dd9459da6e7b893b0c94502f)

Co-authored-by: John Thacker <johnthacker@gmail.com>
---
 epan/dissectors/packet-usb-hid.c | 6 ++++++
 1 file changed, 6 insertions(+)

Index: wireshark-3.6.24/epan/dissectors/packet-usb-hid.c
===================================================================
--- wireshark-3.6.24.orig/epan/dissectors/packet-usb-hid.c
+++ wireshark-3.6.24/epan/dissectors/packet-usb-hid.c
@@ -5318,6 +5318,12 @@ dissect_usb_hid_data(tvbuff_t *tvb, pack
                 if (rdesc->uses_report_id && field->report_id != report_id)
                     continue;
 
+                /* skip items with a report size of 0 (no data and won't
+                 * advance offset) */
+                if (field->report_size == 0) {
+                    continue;
+                }
+
                 /* if the item has no usages, it is padding - HID spec 6.2.2.9 */
                 if (wmem_array_get_count(field->usages) == 0) {
                     proto_tree_add_bits_item(hid_tree, hf_usbhid_padding, tvb, hid_bit_offset, data_size, ENC_LITTLE_ENDIAN);
