The 'get_course_students' function in 'deprecatedlib.php' is returning records by 'LEFT JOINING' the 'user_lastaccess' table on the 'userid' only. This has the effect of returning one record for each occurrence of a user in any course, and not just the one requested. The effect is not noticed except on paged output, because the records are indexed by the userid. On pages output however, the page counts are all off.
The 'LEFT JOIN' needs to include the courseid as a condition. It needs to be part of the join in case there isn't a lastaccess record for a valid user.