That should cause the IOError to be thrown when writing the temp file, so the actual file wouldn't be overwritten, right? I understand there is still a race condition with this fix, but that's why the 1MB buffer is there.