From 9e66a19c8ce25b1e274b8c06f624ed6a123a8ba4 Mon Sep 17 00:00:00 2001 From: RedCommander735 <40245965+RedCommander735@users.noreply.github.com> Date: Sun, 27 Jul 2025 04:56:47 +0200 Subject: [PATCH] fix: ensure offset cannot be greater than data size --- src/usb_hid.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/usb_hid.rs b/src/usb_hid.rs index 2779113..3622ff4 100644 --- a/src/usb_hid.rs +++ b/src/usb_hid.rs @@ -128,6 +128,9 @@ fn write_raw(device: &HidDevice, data: &[u8]) -> Result<()> { fn prepend_byte_and_offset(data: &[u8], offset: usize) -> [u8; 65] { let mut result: [u8; 65] = [0u8; 65]; result[1] = 0x0; + if offset > data.len() { + return result; + } if data.len() - offset < 64 { result[1..].copy_from_slice(&data[offset..]); } else {