[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Accounting for different exception type from base64.b64decode()
commit 264c9e673f71dde707a03ec6b24931f1bd0f3fa4
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sun Jan 27 16:02:06 2013 -0800
Accounting for different exception type from base64.b64decode()
When the base64.b64decode() function encounters a value with malformed padding
it raises a TypeError in python 2.x and a binascii.Error in python 3.x.
======================================================================
ERROR: test_malformed_fingerprint
----------------------------------------------------------------------
Traceback:
File "/home/atagar/Desktop/stem/test/data/python3/test/unit/descriptor/router_status_entry.py", line 231, in test_malformed_fingerprint
self._expect_invalid_attr(content, "fingerprint")
File "/home/atagar/Desktop/stem/test/data/python3/test/unit/descriptor/router_status_entry.py", line 525, in _expect_invalid_attr
entry = RouterStatusEntryV3(content, False)
File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/router_status_entry.py", line 330, in __init__
super(RouterStatusEntryV3, self).__init__(content, validate, document)
File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/router_status_entry.py", line 150, in __init__
self._parse(entries, validate)
File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/router_status_entry.py", line 337, in _parse
_parse_r_line(self, value, validate, True)
File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/router_status_entry.py", line 496, in _parse_r_line
desc.fingerprint = _decode_fingerprint(r_comp[1], validate)
File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/router_status_entry.py", line 703, in _decode_fingerprint
identity_decoded = base64.b64decode(stem.util.str_tools.to_bytes(identity))
File "/usr/lib/python3.2/base64.py", line 92, in b64decode
return binascii.a2b_base64(s)
binascii.Error: Incorrect padding
---
stem/descriptor/router_status_entry.py | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/stem/descriptor/router_status_entry.py b/stem/descriptor/router_status_entry.py
index 7f9875b..ce5a7db 100644
--- a/stem/descriptor/router_status_entry.py
+++ b/stem/descriptor/router_status_entry.py
@@ -17,6 +17,7 @@ sources...
"""
import base64
+import binascii
import datetime
import stem.descriptor
@@ -701,7 +702,7 @@ def _decode_fingerprint(identity, validate):
try:
identity_decoded = base64.b64decode(stem.util.str_tools.to_bytes(identity))
- except TypeError:
+ except (TypeError, binascii.Error):
if not validate:
return None
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits