add message size consistency check

the bulk of a message is stored on disk. a message prefix is stored in the
database (for prefixed headers like "Received:"). this adds a check to ensure
Size = prefix length + on-disk file size.

verifydata also checks for this now.

and one older and one new (since yesterday) bug was found. the first when
appending a message without a header/body section (uncommon). the second when
sending messages from webmail with localserve (uncommon).
This commit is contained in:
Mechiel Lukkien
2023-08-08 22:10:53 +02:00
parent 49cf16d3f2
commit 8c3c12d96a
9 changed files with 259 additions and 17 deletions

View File

@ -404,6 +404,7 @@ func TestSpam(t *testing.T) {
MsgFromValidated: true,
MsgFromValidation: store.ValidationStrict,
Flags: store.Flags{Seen: true, Junk: true},
Size: int64(len(deliverMessage)),
}
for i := 0; i < 3; i++ {
nm := m
@ -503,6 +504,7 @@ func TestDMARCSent(t *testing.T) {
RcptToLocalpart: smtp.Localpart("mjl"),
RcptToDomain: "mox.example",
Flags: store.Flags{Seen: true, Junk: true},
Size: int64(len(deliverMessage)),
}
for i := 0; i < 3; i++ {
nm := m
@ -524,7 +526,7 @@ func TestDMARCSent(t *testing.T) {
})
// Insert a message that we sent to the address that is about to send to us.
var sentMsg store.Message
sentMsg := store.Message{Size: int64(len(deliverMessage))}
tinsertmsg(t, ts.acc, "Sent", &sentMsg, deliverMessage)
err := ts.acc.DB.Insert(ctxbg, &store.Recipient{MessageID: sentMsg.ID, Localpart: "remote", Domain: "example.org", OrgDomain: "example.org", Sent: time.Now()})
tcheck(t, err, "inserting message recipient")