From c94a7b1eff718355417ea49ba98dcd3ff021ca84 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Tue, 22 Jul 2014 17:48:02 -0700 Subject: [PATCH] Make sure "previous counter" is never negative. --- .../main/java/org/whispersystems/libaxolotl/SessionCipher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libaxolotl/src/main/java/org/whispersystems/libaxolotl/SessionCipher.java b/libaxolotl/src/main/java/org/whispersystems/libaxolotl/SessionCipher.java index 2a70a80951..edf2c7c4db 100644 --- a/libaxolotl/src/main/java/org/whispersystems/libaxolotl/SessionCipher.java +++ b/libaxolotl/src/main/java/org/whispersystems/libaxolotl/SessionCipher.java @@ -261,7 +261,7 @@ public class SessionCipher { sessionState.setRootKey(senderChain.first()); sessionState.addReceiverChain(theirEphemeral, receiverChain.second()); - sessionState.setPreviousCounter(sessionState.getSenderChainKey().getIndex()-1); + sessionState.setPreviousCounter(Math.max(sessionState.getSenderChainKey().getIndex()-1, 0)); sessionState.setSenderChain(ourNewEphemeral, senderChain.second()); return receiverChain.second();