transcrypt icon indicating copy to clipboard operation
transcrypt copied to clipboard

Fix listing of file names with special characters to avoid crash and unrecognised names #204

Open jmurty opened this issue 3 months ago β€’ 6 comments

Tweak the file listing to fix two issues found to affect files with problematic names like "Terrible file""")))(((][][].secret.

This change may undo performance improvements achieved in #193.

  • Ensure the git check-attr filter command does not quote file name characters by using -z arg and some extra trickery to keep space and newline delimiter characters for filter metadata and each file name respectively.

    This fixes a file named "Terrible file""")))(((][][].secret being listed as just Terrible file.

  • Adjust checking for filter and crypt strings to work with changed output from check-attr command.

  • Tweak eval 'echo $filename' portion of command to avoid script crash on files with special characters with error message like eval: line 192: syntax error near unexpected token

jmurty avatar Sep 17 '25 16:09 jmurty

This change may undo performance improvements achieved in https://github.com/elasticdog/transcrypt/pull/193.

confirmed 😒

andreineculau avatar Sep 19 '25 19:09 andreineculau

What exactly is the problem? I must be blind, but I've just created a "Terrible file""")))(((][][].secret file and ran my version of transcrypt (it says 2.3.2-pre but I'd have to double-check I don't have any local patches) without an issue πŸ€” I see this is a filename you came up with, but the user didn't yet reply. What issue to you see with your suggested filename?

Do you actually get .git/crypt/transcrypt: eval: line 192: syntax error near unexpected token ('` ?

andreineculau avatar Sep 19 '25 19:09 andreineculau

The problem is when a file with problematic characters – like the "Terrible File" example – is added as a secret/encrypted file, its name gets munged by the _list_encrypted_files() function so that file can no longer be recognised as an encrypted one.

jmurty avatar Sep 23 '25 12:09 jmurty

Thing is... I don't seem to get that error πŸ€” I created a file with the mentioned filename, I staged it, and transcrypt -l was still happy πŸ‘€

andreineculau avatar Sep 24 '25 06:09 andreineculau

Hi @andreineculau are you sure you are checking a file with a problematic name when that file is also encrypted, not just staged as a standard file? The problem manifests as the problematic filename not being included in the output of transcrypt --list when it should be because the file is encrypted.

I have added a unit test that demonstrates the problem with the old transcrypt version from main (efd42e54) and proves that the fix applied on this branch solves it.

I have also made another change in 93ba18f1 which will hopefully improve performance again for repositories like yours with many files, by using an awk command instead of shell loop to handle the null-delimited list of filenames and their filter attributes.

Can you check the performance of this latest version of this PR?

jmurty avatar Sep 27 '25 07:09 jmurty

this is what I see on my end

with the new 94b8599 version

$ pbpaste > transcrypt
$ cp transcrypt .git/crypt/transcrypt
$ echo foo > "\"Difficult file name\"\"\")))(((][][].secret"
$ git add .

$ git status --porcelain
A  "\"Difficult file name\"\"\")))(((][][].secret"
M  transcrypt

$ /usr/bin/time ./transcrypt -l
"Difficult file name""")))(((][][].secret
CONST.inc.secret
        0.34 real         0.18 user         0.13 sys

and with the old version I have (with the changes in #193)

$ echo foo > "\"Difficult file name\"\"\")))(((][][].secret"
$ git add .

$ git status --porcelain
A  "\"Difficult file name\"\"\")))(((][][].secret"

$ /usr/bin/time ./transcrypt -l
CONST.inc.secret

πŸ‘† NOTE that the difficult file is not detected as encrypted!

With the version in 6aa50df --- I just killed ./transcrypt -l after I counted 60 seconds...

So - since we have a test that confirms the fix 🀩 and I can confirm now that the performance is on par with #193 🀩 .... πŸ‘β€οΈπŸš€:shipit:

andreineculau avatar Sep 27 '25 15:09 andreineculau