Fixing this directly even though it is technically vendor code as it has been modified rather heavily (as per #8252).