[Spambayes] [ spambayes-Bugs-696458 ] crash in tokenizer due to bad base64 in subject

SourceForge.net noreply at sourceforge.net
Mon Mar 3 20:41:03 EST 2003


Bugs item #696458, was opened at 2003-03-03 04:12
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=498103&aid=696458&group_id=61702

Category: None
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Sjoerd Mullender (sjoerd)
>Assigned to: Skip Montanaro (montanaro)
Summary: crash in tokenizer due to bad base64 in subject

Initial Comment:
I got a crash in the tokenizer in the line where it does

        x = msg.get('subject', '')
        for x, subjcharset in
email.Header.decode_header(x):

The reason is, the subject of this particular message is

Subject: *****SPAM*****
=?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3IQ?=

which gives a binascii.Error: Incorrect padding from
binascii.a2b_base64.

I am running an up-to-date spambayes and python (i.e.
both fresh from CVS).

Here is a (parial) stack trace:

  File
"/ufs/sjoerd/src/spambayes/spambayes/tokenizer.py",
line 1052, in tokenize
    for tok in self.tokenize_headers(msg):
  File
"/ufs/sjoerd/src/spambayes/spambayes/tokenizer.py",
line 1106, in tokenize_headers
    for x, subjcharset in email.Header.decode_header(x):
  File
"/ufs/sjoerd/src/Python/dist/src/Lib/email/Header.py",
line 92, in decode_header
    dec = email.base64MIME.decode(encoded)
  File
"/ufs/sjoerd/src/Python/dist/src/Lib/email/base64MIME.py",
line 179, in decode
    dec = a2b_base64(s)
binascii.Error: Incorrect padding


----------------------------------------------------------------------

>Comment By: Skip Montanaro (montanaro)
Date: 2003-03-03 22:41

Message:
Logged In: YES 
user_id=44345

Still not clear what the best course of action is at the email package level.
I solved it here by catching the binascii exception and tossing in a
'charset:invalid' token.  It solved the problem here.  Sjoerd, let me know if
it's still a problem for you, but I think this should worm around it.

S

----------------------------------------------------------------------

Comment By: Skip Montanaro (montanaro)
Date: 2003-03-03 11:30

Message:
Logged In: YES 
user_id=44345

Casual observation for anyone reporting spambayes bugs which involve
the email package - You should also check/report such errors on the 
http://mimelib.sourceforge.net/ project, which is where the email
gurus hang out.

----------------------------------------------------------------------

Comment By: Sjoerd Mullender (sjoerd)
Date: 2003-03-03 10:44

Message:
Logged In: YES 
user_id=43607

It seems to me that all calls to email.Header.decode_header
should be protected with try/except, or decode_header itself
should protect itself with a try/except.  A third
possibility is to add an extra indirection through a
function that does basically:

def decode_header(x):
    try:
        return email.Header.decode_header(x)
    except:
        return x


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=498103&aid=696458&group_id=61702



More information about the Spambayes mailing list