From c716ff379b584d64c5c7509fa9de4907c73427c5 Mon Sep 17 00:00:00 2001
From: "Richard T. Carback III" <rick.carback@gmail.com>
Date: Sat, 1 Oct 2022 01:19:13 +0000
Subject: [PATCH] refuse to work when message ID is all 0s

---
 indexedDb/implementation.go | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/indexedDb/implementation.go b/indexedDb/implementation.go
index d6e10517..a2a76124 100644
--- a/indexedDb/implementation.go
+++ b/indexedDb/implementation.go
@@ -160,10 +160,23 @@ func (w *wasmModel) ReceiveMessage(channelID *id.ID,
 	if err != nil {
 		jww.ERROR.Printf("%+v", errors.Wrap(parentErr, err.Error()))
 	}
+
+	if checkZero(messageID.Bytes()) {
+		jww.FATAL.Panicf("Empty message ID is impossible!")
+	}
 	go w.receivedMessageCB(uuid, channelID)
 	return uuid
 }
 
+func checkZero(b []byte) bool {
+	for i := 0; i < len(b); i++ {
+		if b[i] != 0 {
+			return false
+		}
+	}
+	return true
+}
+
 // ReceiveReply is called whenever a message is received that is a reply on a
 // given channel. It may be called multiple times on the same message; it is
 // incumbent on the user of the API to filter such called by message ID.
@@ -183,6 +196,9 @@ func (w *wasmModel) ReceiveReply(channelID *id.ID,
 	if err != nil {
 		jww.ERROR.Printf("%+v", errors.Wrap(parentErr, err.Error()))
 	}
+	if checkZero(messageID.Bytes()) {
+		jww.FATAL.Panicf("Empty message ID is impossible!")
+	}
 	go w.receivedMessageCB(uuid, channelID)
 	return uuid
 }
@@ -205,6 +221,9 @@ func (w *wasmModel) ReceiveReaction(channelID *id.ID, messageID cryptoChannel.Me
 	if err != nil {
 		jww.ERROR.Printf("%+v", errors.Wrap(parentErr, err.Error()))
 	}
+	if checkZero(messageID.Bytes()) {
+		jww.FATAL.Panicf("Empty message ID is impossible!")
+	}
 	go w.receivedMessageCB(uuid, channelID)
 	return uuid
 }
@@ -246,6 +265,9 @@ func (w *wasmModel) UpdateSentStatus(uuid uint64, messageID cryptoChannel.Messag
 	}
 	channelID := &id.ID{}
 	copy(channelID[:], newMessage.ChannelID)
+	if checkZero(messageID.Bytes()) {
+		jww.FATAL.Panicf("Empty message ID is impossible!")
+	}
 	go w.receivedMessageCB(uuid, channelID)
 }
 
-- 
GitLab