# Buggy code
def __decode_address(address_type, offset, data):
    if address_type == ADDRESS_TYPE_IPV4:
        destination_address = socket.inet_ntoa(data[offset : offset + 4])
        offset += 4
    elif address_type == ADDRESS_TYPE_DOMAIN_NAME:
        (domain_length,) = struct.unpack_from("!B", data, offset)
        offset += 1
        destination_address = data[offset : offset + domain_length]
        offset += domain_length
    elif address_type == ADDRESS_TYPE_IPV6:
        raise IPV6AddrError()
    else:
        raise ValueError("Unsupported address type %r" % address_type)

    return offset, destination_address


# Traceback (RuntimeError)
Traceback (most recent call last):
File "/usr/share/tribler/TriblerGUI/event_request_manager.py", line 91, in on_read_data
raise RuntimeError(json_dict["event"]["text"])
RuntimeError: Unhandled Error
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/twisted/python/log.py", line 101, in callWithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "/usr/lib/python2.7/dist-packages/twisted/python/log.py", line 84, in callWithContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "/usr/lib/python2.7/dist-packages/twisted/python/context.py", line 118, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "/usr/lib/python2.7/dist-packages/twisted/python/context.py", line 81, in callWithContext
return func(*args,**kw)
--- <exception caught here> ---
File "/usr/lib/python2.7/dist-packages/twisted/internet/selectreactor.py", line 149, in _doReadOrWrite
why = getattr(selectable, method)()
File "/usr/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 208, in doRead
return self._dataReceived(data)
File "/usr/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 214, in _dataReceived
rval = self.protocol.dataReceived(data)
File "/usr/share/tribler/Tribler/community/tunnel/Socks5/server.py", line 114, in dataReceived
if not self._try_request():
File "/usr/share/tribler/Tribler/community/tunnel/Socks5/server.py", line 169, in _try_request
offset, request = conversion.decode_request(0, self.buffer)
File "/usr/share/tribler/Tribler/community/tunnel/Socks5/conversion.py", line 174, in decode_request
offset, destination_address = __decode_address(address_type, offset, data)
File "/usr/share/tribler/Tribler/community/tunnel/Socks5/conversion.py", line 149, in __decode_address
raise ValueError("Unsupported address type %r" % address_type )
exceptions.ValueError: Unsupported address type 5

# Fixed code
def __decode_address(address_type, offset, data):
    if address_type == ADDRESS_TYPE_IPV4:
        destination_address = socket.inet_ntoa(data[offset : offset + 4])
        offset += 4
    elif address_type == ADDRESS_TYPE_DOMAIN_NAME:
        (domain_length,) = struct.unpack_from("!B", data, offset)
        offset += 1
        destination_address = data[offset : offset + domain_length]
        offset += domain_length
    elif address_type == ADDRESS_TYPE_IPV6:
        raise IPV6AddrError()
    else:
        logger.error("Unsupported address type %r", address_type)
        return offset, None

    return offset, destination_address