This checks if the offset exists before accessing it and also adds unit tests to this function which would have catched this before 🙈 Fixes https://github.com/owncloud/core/issues/14277