This looks like the only unsafe part of this function.