diff --git a/src/add-ons/kernel/drivers/input/usb_hid/HIDDevice.cpp b/src/add-ons/kernel/drivers/input/usb_hid/HIDDevice.cpp index 8028d4d663..aeacd6e43f 100644 --- a/src/add-ons/kernel/drivers/input/usb_hid/HIDDevice.cpp +++ b/src/add-ons/kernel/drivers/input/usb_hid/HIDDevice.cpp @@ -186,7 +186,11 @@ HIDDevice::HIDDevice(usb_device device, const usb_configuration_info *config, return; } - fTransferBuffer = (uint8 *)malloc(fTransferBufferSize); + // We pad the allocation size so that we can always read 32 bits at a time + // (as done in HIDReportItem) without the need for an additional boundary + // check. We don't increase the transfer buffer size though as to not expose + // this implementation detail onto the device when scheduling transfers. + fTransferBuffer = (uint8 *)malloc(fTransferBufferSize + 3); if (fTransferBuffer == NULL) { TRACE_ALWAYS("failed to allocate transfer buffer\n"); fStatus = B_NO_MEMORY;