From 6ea23b8a86104f35f36ebc7b056c352230755e21 Mon Sep 17 00:00:00 2001 From: Evan Su <48808396+HACKERALERT@users.noreply.github.com> Date: Mon, 2 Sep 2024 23:31:51 -0400 Subject: [PATCH] panic if comments are too long No one is going to put >99999 characters in the comment field realistically and the UI is likely to freeze and crash before the application gets to this point. So a raw panic is sufficient for this extreme edge case. --- src/Picocrypt.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Picocrypt.go b/src/Picocrypt.go index 3f995c5..71a7b09 100644 --- a/src/Picocrypt.go +++ b/src/Picocrypt.go @@ -18,6 +18,7 @@ import ( "crypto/hmac" "crypto/rand" "crypto/subtle" + "errors" "flag" "fmt" "hash" @@ -1316,6 +1317,10 @@ func work() { // Write the program version to file _, errs[0] = fout.Write(rsEncode(rs5, []byte(version))) + if len(comments) > 99999 { + panic(errors.New("comments exceed maximum length")) + } + // Encode and write the comment length to file commentsLength := []byte(fmt.Sprintf("%05d", len(comments))) _, errs[1] = fout.Write(rsEncode(rs5, commentsLength))