def get_content_length(environ):
    """Return a positive CONTENT_LENGTH in a safe way (return 0 otherwise)."""
    try:
        return max(0, int(environ.get('CONTENT_LENGTH', 0)))
    except ValueError:
        return 0
