From f245ebe63f40677846127af882ec1e8a0cf20dc8 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 18 Oct 2024 15:08:04 -0700 Subject: [PATCH] Fix bounds check error in duplicate detection --- circuitmatter/session.py | 2 +- requirements.txt | 6 +++--- tests/test_message_reception_state.py | 8 +++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/circuitmatter/session.py b/circuitmatter/session.py index 0e05adb..cb5cad4 100644 --- a/circuitmatter/session.py +++ b/circuitmatter/session.py @@ -324,7 +324,7 @@ def process_counter(self, counter) -> bool: else: new_bitmap = (self.window_bitmap << shift) & self.mask self.window_bitmap = new_bitmap - if 1 < shift < MSG_COUNTER_WINDOW_SIZE: + if 1 <= shift < MSG_COUNTER_WINDOW_SIZE: self.window_bitmap |= 1 << (shift - 1) self.message_counter = counter return False diff --git a/requirements.txt b/requirements.txt index 1e733d3..acc65ac 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -cryptography==41.0.7 -ecdsa==0.18.0 -qrcode==7.4.2 +cryptography +ecdsa +qrcode diff --git a/tests/test_message_reception_state.py b/tests/test_message_reception_state.py index 71b191e..57cd853 100644 --- a/tests/test_message_reception_state.py +++ b/tests/test_message_reception_state.py @@ -12,13 +12,19 @@ def test_basics(): # The current max is not ok assert state.process_counter(123) + # A current max + 1 is ok + assert not state.process_counter(124) + + # Old current max isn't + assert state.process_counter(123) + # A new value is ok assert not state.process_counter(126) # assert state.process_counter(123) - assert not state.process_counter(124) + assert state.process_counter(124) assert not state.process_counter(125)