Closed Bug 152468 Opened 24 years ago Closed 24 years ago

string truncation causes filter misses

Categories

(MailNews Core :: Filters, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
mozilla1.1beta

People

(Reporter: dmosedale, Assigned: dmosedale)

References

Details

Attachments

(1 file)

I was seeing some filter misses that I didn't expect in my spam filters, so I started putting printfs in the code. The problem seems to happen at nsMsgBodyHandler::GetNextLine around this line of code: while (eatThisLine && length >= 0); // if we hit eof, make sure we break out of this loop. Bug #: return length; What ends up happening is that sometimes -1 gets returned, and then the next call to GetNextLine ends up down in GetNextFilterLine in this code: else if (m_headersSize == 0) { buf[0] = '\0'; } Which causes the last byte of the previous header to be overwritten with null. It's possible that just changing the while loop to look for length > 0 is the correct fix; I'm not entirely sure.
-> Navin
Assignee: bienvenu → naving
dmose, can you elaborate what type of filters you have ? thx.
These are filters that are filtering over IMAP against "custom header". Example filter: name="spam: content-type" enabled="yes" type="1" action="Move to folder" actionValue="imap://dmose@imap.meer.net/Potential Spam" condition="AND (\"Content-Type\",contains,charset=) AND (\"Content-Type\",doesn't contain,charset=us-ascii) AND (\"Content-Type\",doesn't contain,charset=iso-8859-1) AND (\"Content-Type\",doesn't contain,charset=\\"us-ascii\\") AND (\"Content-Type\",doesn't contain,charset=\\"iso-8859-1\\")" This filter often incorrectly matches one of the last two and conditions because the final quote mark has been trounced by a null.
My initial diagnosis was wrong. The real problem here is that nsParseMailMessageState::FinalizeHeaders() is destructive, and writes NULLs into the header in several places (notably Message-ID, Content-Type: charset= , and Newsgroups) in order to cheaply truncate strings.
I've got a patch... taking.
Assignee: naving → dmose
Summary: off-by-one error causes filter misses → string truncation causes filter misses
Target Milestone: --- → mozilla1.1beta
Status: NEW → ASSIGNED
Attached patch patch, v1 — — Splinter Review
Generate new truncated strings, rather than writing into ones that should be read-only. This is the right fix, assuming nothing else depends on the old behaviorial side-effects (which seems fairly unlikely).
So, in this instance, to be clear, you were counting on the trailing " in the charset header to be there. This fix looks OK to me, but the other alternative is to simply save and restore the crunched character(s) instead of copying the string, which would be faster.
bienvenu: yes on all counts. I considered doing the crunch/restore solution, but it was clear that this data was already shared, and not being confident that I understood all the sharing that was going on, I had threadsafety fears. I also didn't like the fact that it forces us to violate |const char *|-typed data. What would you prefer I do?
Comment on attachment 90360 [details] [diff] [review] patch, v1 sr=bienvenu
Attachment #90360 - Flags: superreview+
there aren't any threadsafety issues - this data is only manipulated on the ui thread. However, I think the copying is OK. It's not going to slow us down appreciably.
Comment on attachment 90360 [details] [diff] [review] patch, v1 r=naving
Attachment #90360 - Flags: review+
Fix checked in.
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
Product: MailNews → Core
Product: Core → MailNews Core
Regressions: 2067209
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: