Repository navigation
Conversation
…ense IMU The report classes are 1-byte packed so their layout is the wire format, which puts multi-byte members at odd offsets. Plain member access in a packed class is fine (the compiler emits misalignment-safe code), but a std::array member is not: its member functions and references to its elements assume natural alignment. UBSan flagged every SpaceMouse axis setter, getter and reset() in hid_rp_reports_host_test, and the DualSense get_imu_data() returned a reference to an odd address. - SpaceMouseTranslationInputReport / SpaceMouseRotationInputReport: three int16_t members instead of std::array<int16_t, 3> (same layout and sizeof); the formatters read them through the by-value getters, since fmt takes its arguments by reference. - PlaystationDualsenseBLEComplexInputReport: set_imu_data() / get_imu_data() go through the packed gyro / accel members, and get_imu_data() returns a copy instead of a misaligned reference. Tests: the SpaceMouse getters, reset() and formatters, and a DualSense IMU round trip with its little-endian wire bytes. The hid-rp host tests run clean under UBSan. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
Contributor
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
2 open issues
What changed in this PR
Fixes UBSan-detected undefined behavior caused by misaligned access to multi-byte fields inside 1-byte-packed HID report layouts (SpaceMouse axes and DualSense IMU).
Changes:
- Replace SpaceMouse
std::array<int16_t, 3>axes storage with plainint16_tmembers and update formatters to use by-value getters. - Rework DualSense IMU accessors to copy through packed
gyro/accelmembers and return IMU data by value. - Add host tests covering SpaceMouse getters/reset/formatting and DualSense IMU set/get + little-endian wire bytes.
| File | Description |
|---|---|
| components/hid-rp/test/hid_rp_reports_host_test.cpp | Adds regression tests for packed/misaligned axis/IMU access and formatter behavior. |
| components/hid-rp/include/hid-rp-playstation.hpp | Makes IMU accessors alignment-safe by copying through packed members; updates docs. |
| components/hid-rp/include/hid-rp-3dconnexion.hpp | Replaces misalignment-unsafe std::array axis storage with plain packed members. |
| components/hid-rp/include/hid-rp-3dconnexion-formatters.hpp | Avoids referencing packed members by formatting via by-value getters. |
Review effort: Lite
|
✅Static analysis result - no issues found! ✅ |
…here (review) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
Copilot stopped reviewing on behalf of
finger563 due to an error
December 2, 2026 05:51
This branch has not been deployed
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.

What
hid-rp's report classes are 1-byte packed so that their layout is the wire format. That puts multi-byte members at odd offsets.
report.xin a packed class, the compiler knows the member may be misaligned and emits safe code.std::arraymember is not. Its member functions (operator[],fill) and any reference to an element assume natural alignment, so each of those accesses is undefined behavior.Running the component host tests under UBSan, which CI doesn't do yet, flagged every SpaceMouse axis setter, getter and
reset(). A targeted probe showed the DualSenseget_imu_data()returning a reference to an odd address.Changes
SpaceMouseTranslationInputReport/SpaceMouseRotationInputReport: threeint16_tmembers instead ofstd::array<int16_t, 3> axes.sizeofare unchanged, and so is the public API.PlaystationDualsenseBLEComplexInputReport:set_imu_data()andget_imu_data()go through the packedgyro/accelmembers.get_imu_data()now returns a copy instead of aconst&. Nothing in espp calls it.imuarray member stays, for compatibility, with a note to use the accessors orgyro/accelinstead.Tests
reset()and both formatters.The four hid-rp host test suites run with zero UBSan reports, where
hid_rp_reports_host_testhad 19 before. They build without warnings with g++ 16, and all 40 component host tests pass.Not in this PR
FifoPacket*structs: nothing in espp uses those structs, so it's latent.🤖 Generated with Claude Code
https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU