[issue38332] invalid content-transfer-encoding in encoded-word causes KeyError

2019-10-12 Thread Abhilash Raj


Change by Abhilash Raj :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
versions:  -Python 3.5, Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38332] invalid content-transfer-encoding in encoded-word causes KeyError

2019-10-12 Thread miss-islington


miss-islington  added the comment:


New changeset e540bb546163f108c7c304f2e6865efaa78cd4c2 by Miss Islington (bot) 
in branch '3.8':
bpo-38332: Catch KeyError from unknown cte in encoded-word. (GH-16503)
https://github.com/python/cpython/commit/e540bb546163f108c7c304f2e6865efaa78cd4c2


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38332] invalid content-transfer-encoding in encoded-word causes KeyError

2019-10-12 Thread miss-islington


miss-islington  added the comment:


New changeset febe359559781019c0c8432a2f768809d00af6af by Miss Islington (bot) 
in branch '3.7':
bpo-38332: Catch KeyError from unknown cte in encoded-word. (GH-16503)
https://github.com/python/cpython/commit/febe359559781019c0c8432a2f768809d00af6af


--
nosy: +miss-islington

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38332] invalid content-transfer-encoding in encoded-word causes KeyError

2019-10-05 Thread miss-islington


Change by miss-islington :


--
pull_requests: +16185
pull_request: https://github.com/python/cpython/pull/16597

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38332] invalid content-transfer-encoding in encoded-word causes KeyError

2019-10-05 Thread miss-islington


Change by miss-islington :


--
pull_requests: +16184
pull_request: https://github.com/python/cpython/pull/16596

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38332] invalid content-transfer-encoding in encoded-word causes KeyError

2019-10-05 Thread Abhilash Raj


Abhilash Raj  added the comment:


New changeset 65dcc8a8dc41d3453fd6b987073a5f1b30c5c0fd by Abhilash Raj (Andrei 
Troie) in branch 'master':
bpo-38332: Catch KeyError from unknown cte in encoded-word. (GH-16503)
https://github.com/python/cpython/commit/65dcc8a8dc41d3453fd6b987073a5f1b30c5c0fd


--
nosy: +maxking

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38332] invalid content-transfer-encoding in encoded-word causes KeyError

2019-10-01 Thread Emmanuel Arias


Emmanuel Arias  added the comment:

Hi Andrei sorry for my last message. Now I understand perfectly your idea and 
your PR. IMO this is a correct patch.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38332] invalid content-transfer-encoding in encoded-word causes KeyError

2019-10-01 Thread Andrei Troie


Andrei Troie  added the comment:

I agree with you that according to the RFC, the cte can of course only be "B" 
or "Q". My point is that, in my example, if you try to do that you get a 
KeyError propagating all the way down to email.message.get(), which I believe 
is incorrect. 

Consider an encoded word which is syntactically incorrect in a different way, 
like  if for instance it's missing the terminating '?=':

'=?UTF-8?Q?somevalue'

Currently, this case will cause _encoded_words.py to throw a ValueError on this 
line:

_, charset, cte, cte_string, _ = ew.split('?')

Which is then caught by _header_value_parser.get_encoded_word() and handled 
appropriately.

To me this is the same kind of thing. I agree that an exception should be 
thrown, I just don't think it should propagate all the way back to the caller 
of email.message.get().

On a separate note, I agree with you that perhaps _encoded_words.decode() 
should throw more specific exceptions instead of ValueError and KeyError but 
that's a separate thing. I can fix that if you prefer.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38332] invalid content-transfer-encoding in encoded-word causes KeyError

2019-10-01 Thread Andrei Troie


Change by Andrei Troie :


--
keywords: +patch
pull_requests: +16094
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/16503

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38332] invalid content-transfer-encoding in encoded-word causes KeyError

2019-09-30 Thread Emmanuel Arias


Emmanuel Arias  added the comment:

Hello,

I am not a email expert, but according to RFC 1342 the enconding can be either 
"B" or "Q". So, I think is reasonable that when a not correct enconding is set, 
should be raise an exception


I think that we can improve the message raising a more specific Exception

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38332] invalid content-transfer-encoding in encoded-word causes KeyError

2019-09-30 Thread Emmanuel Arias


Change by Emmanuel Arias :


--
nosy: +eamanu

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38332] invalid content-transfer-encoding in encoded-word causes KeyError

2019-09-30 Thread Andrei Troie


New submission from Andrei Troie :

The following will cause a KeyError on email.message.get()

import email
import email.policy

text = "Subject: =?us-ascii?X?somevalue?="
eml = email.message_from_string(text, policy=email.policy.default)
eml.get('Subject')

This is caused by the fact that the code in _encoded_words.py assumes the 
content-transfer-encoding of an encoded-word is always 'q' or 'b' (after 
lowercasing): 
https://github.com/python/cpython/blob/aca8c406ada3bb547765b262bed3ac0cc6be8dd3/Lib/email/_encoded_words.py#L178

I realise it's probably a silly edge case and I haven't (yet) encountered 
something like this in the wild, but it does seem contrary to the spirit of the 
email library to raise an exception like this that can propagate all the way to 
email.message.get().

--
components: email
messages: 353624
nosy: aft90, barry, r.david.murray
priority: normal
severity: normal
status: open
title: invalid content-transfer-encoding in encoded-word causes KeyError
type: crash
versions: Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com