Fix PubSub DataSetWriter sequence number uint16 overflow#1955
Merged
Conversation
The sequence number in DataSetWriter.generate_uadp_dataset() incremented without bound, causing a struct.pack overflow when the value exceeded 65535 (UInt16 max). At 30Hz publishing frequency, this crashes the writer after ~36 minutes. Wrap the sequence number using modulo arithmetic so it cycles from 65535 back to 1, matching the valid UInt16 range. Closes FreeOpcUa#1953 Signed-off-by: Lidang-Jiang <lidangjiang@gmail.com>
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.
Summary
DataSetWriter.generate_uadp_dataset()that crashes the PubSub writer after 65535 messagesChanges
asyncua/pubsub/writer.py: Wrap sequence number with modulo arithmetic:self._seq_no = (self._seq_no % 65535) + 1tests/test_pubsub.py: Add regression test verifying sequence number wraps from 65535 back to 1Root Cause
self._seq_no += 1increments without bound. WhenUInt16(self._seq_no)is serialized viastruct.pack('<H', value)with a value > 65535, it raisesstruct.error. At 30Hz publishing frequency, this crashes the writer after ~36 minutes.Fix
Use
(self._seq_no % 65535) + 1so the sequence number cycles within [1, 65535], matching the valid UInt16 range.Before (overflow demonstration)
After (fix verified)
Test output
Test plan