Fix bounds check error in duplicate detection

This commit is contained in:
Scott Shawcroft 2024-10-18 15:08:04 -07:00
parent 75d4050307
commit f245ebe63f
No known key found for this signature in database
3 changed files with 11 additions and 5 deletions

View file

@ -324,7 +324,7 @@ class MessageReceptionState:
else: else:
new_bitmap = (self.window_bitmap << shift) & self.mask new_bitmap = (self.window_bitmap << shift) & self.mask
self.window_bitmap = new_bitmap 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.window_bitmap |= 1 << (shift - 1)
self.message_counter = counter self.message_counter = counter
return False return False

View file

@ -1,3 +1,3 @@
cryptography==41.0.7 cryptography
ecdsa==0.18.0 ecdsa
qrcode==7.4.2 qrcode

View file

@ -12,13 +12,19 @@ def test_basics():
# The current max is not ok # The current max is not ok
assert state.process_counter(123) 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 # A new value is ok
assert not state.process_counter(126) assert not state.process_counter(126)
# #
assert state.process_counter(123) assert state.process_counter(123)
assert not state.process_counter(124) assert state.process_counter(124)
assert not state.process_counter(125) assert not state.process_counter(125)