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.
This commit is contained in:
Evan Su 2024-09-02 23:31:51 -04:00
parent e8fe27855f
commit 6ea23b8a86

View file

@ -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))