diff: fail generation if a file changes size When we know that we know a file's size, and the file's size changes, fail.
diff --git a/src/diff_file.c b/src/diff_file.c
index 9804a94..c7e9fbe 100644
--- a/src/diff_file.c
+++ b/src/diff_file.c
@@ -338,15 +338,15 @@ static int diff_file_content_load_workdir_file(
if (error < 0)
goto cleanup;
- /* if file size doesn't match cached value, abort */
- if (fc->file->size && fc->file->size != new_file_size) {
+ if (!(fc->file->flags & GIT_DIFF_FLAG_VALID_SIZE)) {
+ fc->file->size = new_file_size;
+ fc->file->flags |= GIT_DIFF_FLAG_VALID_SIZE;
+ } else if (fc->file->size != new_file_size) {
git_error_set(GIT_ERROR_FILESYSTEM, "file changed before we could read it");
error = -1;
goto cleanup;
}
- fc->file->size = new_file_size;
-
if ((diff_opts->flags & GIT_DIFF_SHOW_BINARY) == 0 &&
diff_file_content_binary_by_size(fc))
goto cleanup;