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