[PATCH 03/10] parser: codec lookup fails when a NUL (\x00) is in the name

Andrew Donnellan andrew.donnellan at au1.ibm.com
Wed Jun 28 18:17:55 AEST 2017


On 28/06/17 17:48, Daniel Axtens wrote:
> On Python3 this presents as a ValueError
> On Python2 this presents as a TypeError
>
> In both cases, catch these exceptions.
>
> Signed-off-by: Daniel Axtens <dja at axtens.net>

This is the kind of error which one would only ever find by fuzzing...

Error classes appear correct

Reviewed-by: Andrew Donnellan <andrew.donnellan at au1.ibm.com>

> ---
>  patchwork/parser.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/patchwork/parser.py b/patchwork/parser.py
> index 3ab4eb3d2011..19ed7ca4e315 100644
> --- a/patchwork/parser.py
> +++ b/patchwork/parser.py
> @@ -436,7 +436,7 @@ def _find_content(mail):
>              if charset is not None:
>                  try:
>                      codecs.lookup(charset)
> -                except LookupError:
> +                except (LookupError, ValueError, TypeError):
>                      charset = None
>
>              # If there is no charset or if it is unknown, then try some common
>

-- 
Andrew Donnellan              OzLabs, ADL Canberra
andrew.donnellan at au1.ibm.com  IBM Australia Limited



More information about the Patchwork mailing list