summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2022-02-11 17:54:34 -0500
committerEdward Thomson <ethomson@github.com>2022-02-11 18:00:14 -0500
commit0200e510f77991a3c3aa6f89c390a666170deb0f (patch)
tree633a1982b0c3915cc106fabb52c06ab2272d5975
parent458547bd397473fd7664484510a075c18a7b55ab (diff)
downloadlibgit2-ethomson/fix-stale-filesize-crash.tar.gz
diff: fail generation if a file changes sizeethomson/fix-stale-filesize-crash
When we know that we know a file's size, and the file's size changes, fail.
-rw-r--r--src/diff_file.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/diff_file.c b/src/diff_file.c
index 9804a943c..c7e9fbeee 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;