Subject: bug#48902: 28.0.50; Directory names containing apostrophes and backticks cause problems

From: Mattias Engdegård <[email-masked]>
Date: Wed, 9 Jun 2021 13:40:18 +0200

8 juni 2021 kl. 22.33 skrev Alan Third <[email-masked]>:

> It's not just allocInitFromFile, I'm looking at the other callers of
> image_find_image_file and they all call ENCODE_FILE after it too.
> 
> The only direct caller of image_find_image_fd that actually uses the
> contents of the returned string (svg_load) also encodes the file name.
> 
> So I think we could restrict the use of the encoded filename within
> image_find_image_fd to *only* when it actually opens the file.

Thank you, and I arrived at the same conclusion.

> Patch attached. I've tested it here but I only have a couple of images
> to try it with.

Looks fine, but the image_find_image_file comment needs to be amended since it says that it returns an encoded string.

> I've been looking at the other changes I made in
> 747a923b9a35533f98573ad5b01fccf096195079 and I'm not sure they're
> correct. They clearly work now, but most of the time it's probably
> simple ASCII which should pass easily.
> 
> Before they *all* seem to have assumed the data was UTF8 encoded,
> which is surely wrong since most of the time it's coming from Emacs.
> It's things like menu item titles.
> 
> These are the use cases stringWithLispString was designed for, right?
> The only odd one is image filenames because they're explicitly encoded?

I should think so -- stringWithLispString: was designed as a general-purpose method to convert from a lisp string to NSString without changing the contents. Non-Unicode values (which includes raw bytes) become U+FFFD except surrogates as they can be represented (in a manner of speaking) in UTF-16, and it turns out to be more useful that way.

Furthermore, if we use stringWithLispString: for file names, no special file name encoding step should be needed on our side, since the NS libs will perform any needed normalisation (at least if I've understood it right).