Re: [PATCH 04/10] parser: catch failures in decoding headers

2017-06-28 Thread Stephen Finucane
On Wed, 2017-06-28 at 17:48 +1000, Daniel Axtens wrote:
> Headers can fail to decode:
>  - if a part cannot be encoded as ascii
>  - if the coding hint names a codec that doesn't exist
>  - if there's a null byte in the codec name
> 
> Catch these errors.
> 
> Signed-off-by: Daniel Axtens 

Reviewed-by: Stephen Finucane 

and applied.

___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork


Re: [PATCH 04/10] parser: catch failures in decoding headers

2017-06-28 Thread Andrew Donnellan

On 28/06/17 17:48, Daniel Axtens wrote:

Headers can fail to decode:
 - if a part cannot be encoded as ascii
 - if the coding hint names a codec that doesn't exist
 - if there's a null byte in the codec name

Catch these errors.

Signed-off-by: Daniel Axtens 


Reviewed-by: Andrew Donnellan 


---
 patchwork/parser.py | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/patchwork/parser.py b/patchwork/parser.py
index 19ed7ca4e315..032af8a7be7c 100644
--- a/patchwork/parser.py
+++ b/patchwork/parser.py
@@ -90,9 +90,11 @@ def sanitise_header(header_contents, header_name=None):
 header = make_header(value,
  header_name=header_name,
  continuation_ws='\t')
-except UnicodeDecodeError:
-# At least one of the parts cannot be encoded as ascii.
-# Find out which one and fix it somehow.
+except (UnicodeDecodeError, LookupError, ValueError, TypeError):
+#  - a part cannot be encoded as ascii. (UnicodeDecodeError), or
+#  - we don't have a codec matching the hint (LookupError)
+#  - the codec has a null byte (Py3 ValueError/Py2 TypeError)
+# Find out which part and fix it somehow.
 #
 # We get here under Py2 when there's non-7-bit chars in header,
 # or under Py2 or Py3 where decoding with the coding hint fails.



--
Andrew Donnellan  OzLabs, ADL Canberra
andrew.donnel...@au1.ibm.com  IBM Australia Limited

___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork


[PATCH 04/10] parser: catch failures in decoding headers

2017-06-28 Thread Daniel Axtens
Headers can fail to decode:
 - if a part cannot be encoded as ascii
 - if the coding hint names a codec that doesn't exist
 - if there's a null byte in the codec name

Catch these errors.

Signed-off-by: Daniel Axtens 
---
 patchwork/parser.py | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/patchwork/parser.py b/patchwork/parser.py
index 19ed7ca4e315..032af8a7be7c 100644
--- a/patchwork/parser.py
+++ b/patchwork/parser.py
@@ -90,9 +90,11 @@ def sanitise_header(header_contents, header_name=None):
 header = make_header(value,
  header_name=header_name,
  continuation_ws='\t')
-except UnicodeDecodeError:
-# At least one of the parts cannot be encoded as ascii.
-# Find out which one and fix it somehow.
+except (UnicodeDecodeError, LookupError, ValueError, TypeError):
+#  - a part cannot be encoded as ascii. (UnicodeDecodeError), or
+#  - we don't have a codec matching the hint (LookupError)
+#  - the codec has a null byte (Py3 ValueError/Py2 TypeError)
+# Find out which part and fix it somehow.
 #
 # We get here under Py2 when there's non-7-bit chars in header,
 # or under Py2 or Py3 where decoding with the coding hint fails.
-- 
2.11.0

___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork