Skip to content

Fix silent overflow in 24/40/48/56-bit integer packing - #687

Open
VolMax-Studio wants to merge 1 commit into
canopen-python:masterfrom
VolMax-Studio:fix/narrow-integer-pack-range
Open

VolMax-Studio wants to merge 1 commit into
canopen-python:masterfrom
VolMax-Studio:fix/narrow-integer-pack-range

Conversation

@VolMax-Studio

Copy link
Copy Markdown

UnsignedN.pack() and IntegerN.pack() pack into a wider standard integer type and truncate the result. For 24-, 40-, 48-, and 56-bit types, values outside the declared width can therefore wrap silently rather than raise an error.

Validate the narrow-width range after struct.Struct.pack(), preserving struct.error internally and the existing ODVariable.encode_raw() ValueError behavior.

Regression tests cover both signed and unsigned boundaries, invalid values, and the public encoding API. All tests run against current master.

Validation

  • pytest -q: 283 passed, 1 skipped (231 subtests passed).
  • unittest discover -s . -p 'test_*.py' -q: 284 tests, OK (1 skipped).
  • ruff check canopen/objectdictionary/datatypes.py test/test_od.py: passed.

Signed-off-by: VolMax-Studio <volmax.core@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant