Last-effort method for avoiding infinite loop if data to be written is not devideable by 512 (untested because I don't know how to test)