diff options
author | Edward Thomson <ethomson@github.com> | 2022-02-11 17:54:34 -0500 |
---|---|---|
committer | Edward Thomson <ethomson@github.com> | 2022-02-11 18:00:14 -0500 |
commit | 0200e510f77991a3c3aa6f89c390a666170deb0f (patch) | |
tree | 633a1982b0c3915cc106fabb52c06ab2272d5975 | |
parent | 458547bd397473fd7664484510a075c18a7b55ab (diff) | |
download | libgit2-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.c | 8 |
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; |