Skip to content

Commit 17a9020

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 7c129cd commit 17a9020

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

commands.cpp

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

773+
if (file_size == 0) {
774+
return 0;
775+
}
776+
773777
// We use an HMAC of the file as the encryption nonce (IV) for CTR mode.
774778
// By using a hash of the file we ensure that the encryption is
775779
// deterministic so git doesn't think the file has changed when it really
@@ -887,6 +891,11 @@ int smudge (int argc, const char** argv)
887891
// Read the header to get the nonce and make sure it's actually encrypted
888892
unsigned char header[10 + Aes_ctr_decryptor::NONCE_LEN];
889893
std::cin.read(reinterpret_cast<char*>(header), sizeof(header));
894+
895+
if (std::cin.gcount() == 0) {
896+
return 0;
897+
}
898+
890899
if (std::cin.gcount() != sizeof(header) || std::memcmp(header, "\0GITCRYPT\0", 10) != 0) {
891900
// File not encrypted - just copy it out to stdout
892901
std::clog << "git-crypt: Warning: file not encrypted" << std::endl;

0 commit comments

Comments
 (0)