Skip to content

Commit 62c3725

Browse files
committed
Keep empty files unencrypted
To work around the issue that git considers the working directory dirty when empty files are encrypted, these are kept untouched when cleaning/smudging. Security wise, this is not an issue, as you can check if an encrypted file is empty due to the deterministic encryption properties.
1 parent 546664f commit 62c3725

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

commands.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,10 @@ int clean (int argc, const char** argv)
748748
return 1;
749749
}
750750

751+
if (file_size == 0) {
752+
return 0;
753+
}
754+
751755
// We use an HMAC of the file as the encryption nonce (IV) for CTR mode.
752756
// By using a hash of the file we ensure that the encryption is
753757
// deterministic so git doesn't think the file has changed when it really
@@ -865,6 +869,11 @@ int smudge (int argc, const char** argv)
865869
// Read the header to get the nonce and make sure it's actually encrypted
866870
unsigned char header[10 + Aes_ctr_decryptor::NONCE_LEN];
867871
std::cin.read(reinterpret_cast<char*>(header), sizeof(header));
872+
873+
if (std::cin.gcount() == 0) {
874+
return 0;
875+
}
876+
868877
if (std::cin.gcount() != sizeof(header) || std::memcmp(header, "\0GITCRYPT\0", 10) != 0) {
869878
// File not encrypted - just copy it out to stdout
870879
std::clog << "git-crypt: Warning: file not encrypted" << std::endl;

0 commit comments

Comments
 (0)