all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Daniel Brooks <db48x@db48x.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: cpitclaudel@gmail.com, emacs-devel@gnu.org, stefan@marxist.se,
	monnier@iro.umontreal.ca, yuri.v.khan@gmail.com
Subject: Re: Unicode confusables and reordering characters considered harmful,  a simple solution
Date: Thu, 04 Nov 2021 19:23:08 -0700	[thread overview]
Message-ID: <87k0hnqr1v.fsf@db48x.net> (raw)
In-Reply-To: <83o870fjqg.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 04 Nov 2021 09:44:23 +0200")

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Daniel Brooks <db48x@db48x.net>

>> Of course it will show them in the comments and strings.
>
> Then this visual noise will get in the way of people's reading those
> comments and strings, and, for strings, will make it very hard to
> understand what will be presented to the user when those strings are
> output in some UI.
>
>> That’s where the problem is.
>
> No, the problem is elsewhere entirely: it's in the punctuation
> characters unrelated to strings and comments whose directionality is
> overridden, and which thus display in places that cause incorrect
> visual interpretation of the program during a casual read.

Look at the examples again. In many of them, all of the bidi override
characters are inside a string or comment. When that is the case, these
characters are only a problem if they cause characters that are inside
the string or comment to appear to be outside of it, by reordering those
characters relative to the syntactic markers for the string or
comment. In other examples these characters are _outside_ the string or
comment.

Unless Emacs has specific knowledge of the language syntax, showing the
characters is the only sure way to know if there is a problem or not.

> You misunderstand the cause.  The mere presence of these characters is
> NOT the root cause.  These characters are legitimate and helpful when
> used as intended.  See TUTORIAL.he for a pertinent example.

Please don’t presume to tell me what I do or don’t understand. Yes,
there are use cases which are not harmful, but as I have said it must be
up to either the programmer or the compiler to answer that
question. Emacs doesn’t know the syntax of every programming language.

>> Furthermore, I have not suggested that showing the characters needs to
>> preclude any other form of highlighting. If you wish to develop some
>> additional way of warning the developer, please do so.
>
> We are talking about what should be in Emacs.  What you suggest
> shouldn't.

No other suggested feature will be useful to me. This one will. I
suggest to you that you do not know what all users want.

>> However, I suspect that the compilers for most languages currently in
>> active development will develop their own warnings and error messages as
>> well. We have plenty of ways for those messages to show up inside Emacs
>> as highlights.
>
> That's a tangent.  We are discussing what Emacs should do as a
> programmer's editor to flag such suspicious code.  That shouldn't need
> a compiler if we can do the job ourselves.  And we can.

This is not a tangent. Emacs relies heavily on compilers and language
runtimes for many of its features. This is just one more area where
Emacs should not try to be too clever.

>
>> Rust, for example, has already done so. Here’s an example:
>> 
>>     error: unicode codepoint changing visible direction of text present in comment
>>       --> src/pathmap/path.rs:10:5
>>        |
>>     10 |     /* } if is_admin  begin admins only */
>>        |     ^^-^^-^^^^^^^^^^--^^^^^^^^^^^^^^^^^^^^
>>        |     | |  |          ||
>>        |     | |  |          |'\u{2066}'
>>        |     | |  |          '\u{2069}'
>>        |     | |  '\u{2066}'
>>        |     | '\u{202e}'
>>        |     this comment contains invisible unicode text flow control codepoints
>>        |
>>        = note: `#[deny(text_direction_codepoint_in_comment)]` on by default
>>        = note: these kind of unicode codepoints change the way text
>> flows on applications that support them, but can cause confusion
>> because they change the order of characters on the screen
>>        = help: if their presence wasn't intentional, you can remove them
>
> Since the Rust compiler evidently does this when it finds these
> characters inside comments (and probably also inside strings), IMNSHO
> this is a terrible misfeature, because it means code that uses those
> controls in legitimate ways cannot be compiled without tweaking
> non-default options.  That's a cop-out, not the way to flag the
> problematic cases.

Your conclusion here is incorrect. Rust has choosen a fast strategy,
where they implement a broad error today (well, four days ago) knowing
that it does not prevent them from introducing a more refined error or
set of errors later.

Rust also has a very flexible annotation system that allows the
programmer to annotate specific statements and language items. If a use
of these characters is determined to be legitimate, the programmer can
annotate the comment, or the function the comment is in, so that this
error is disabled. In projects with strong review culture, seeing that
annotation while doing a code review will be a very strong signal that
something unusual is going on, and that it needs to be considered
carefully. Annotations are are a great feature of Rust that I do not
expect Emacs to take into account.

Instead I think that Emacs should adopt a similar fast
strategy. Anything we do today can be refined later.

>> Naturally that already shows up inside of Emacs just fine; see the
>> attached image.
>
> I think this is terrible.  At best, it only tells you that something
> non-trivial goes on here (but what exactly?).  At worst, it looks like
> corruption of the source.  And while in the malicious case treating
> that as corruption is not such a bad idea, all the valid uses of these
> characters will also look like corruption.  Which means the cure is
> probably worse than the disease, because the malicious cases are a
> tiny fraction of the valid ones.

I cannot believe that you really think this. It shows up with exactly the
same highlighting that your recently–introduced
highlight-confusing-reorderings function uses. It looks nothing like
“corruption of the source”, whatever you may mean by that. The error
message explains _exactly_ what the compiler is guarding against.

Also, thinking about fractions here is irrelevant. The Rust team
examined the source of every Rust crate every published on
https://crates.io, and found only 5 that even used these
characters. With a sample size that small, percentages don’t mean much.

https://blog.rust-lang.org/2021/11/01/cve-2021-42574.html

> It's the same kind of "solution" like the airport security after 9/11:
> because there was a bunch of terrorists, we are all now suspect as
> potential terrorists, and for that reason we are constantly delayed
> for hours and humiliated by endless frisking.

Now I think you are being deliberately insulting. I conclude that your
only purpose in this conversation was to troll people or to say no to
any solution you didn’t think of yourself.

Yours doesn’t even work with `next-error`. Useless.

db48x



  parent reply	other threads:[~2021-11-05  2:23 UTC|newest]

Thread overview: 172+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-02 12:57 Unicode confusables and reordering characters considered harmful Vasilij Schneidermann
2021-11-02 13:18 ` Po Lu
2021-11-02 13:54   ` Uwe Brauer
2021-11-02 14:53     ` Eli Zaretskii
2021-11-02 15:16       ` Eli Zaretskii
2021-11-02 15:21         ` Uwe Brauer
2021-11-02 16:24       ` Clément Pit-Claudel
2021-11-02 16:47         ` Eli Zaretskii
2021-11-02 17:01           ` Stefan Kangas
2021-11-02 17:10             ` Eli Zaretskii
2021-11-02 18:43               ` Stefan Kangas
2021-11-02 18:49                 ` Eli Zaretskii
2021-11-02 19:12                   ` Stefan Monnier
2021-11-02 19:36                     ` Eli Zaretskii
2021-11-02 19:47                       ` Stefan Monnier
2021-11-02 19:51                         ` Eli Zaretskii
2021-11-02 21:28                           ` Unicode confusables and reordering characters considered harmful, a simple solution Daniel Brooks
2021-11-03 13:30                             ` Eli Zaretskii
2021-11-03 17:41                             ` Yuri Khan
2021-11-03 17:56                               ` Eli Zaretskii
2021-11-03 18:20                                 ` Juri Linkov
2021-11-03 19:02                                   ` Gregory Heytings
2021-11-03 19:46                                     ` Eli Zaretskii
2021-11-03 19:58                                       ` Yuri Khan
2021-11-03 20:21                                       ` Gregory Heytings
2021-11-03 20:31                                         ` Eli Zaretskii
2021-11-03 21:16                                           ` Gregory Heytings
2021-11-04  7:16                                             ` Eli Zaretskii
2021-11-04  9:06                                               ` Gregory Heytings
2021-11-04  9:19                                                 ` Eli Zaretskii
2021-11-04  9:48                                                   ` Eli Zaretskii
2021-11-04  8:44                                     ` Juri Linkov
2021-11-03 18:45                                 ` Yuri Khan
2021-11-03 19:09                                   ` Eli Zaretskii
2021-11-03 19:35                                     ` Yuri Khan
2021-11-03 20:01                                       ` Eli Zaretskii
2021-11-03 20:45                                         ` Gregory Heytings
2021-11-03 20:53                                           ` Eli Zaretskii
2021-11-03 21:23                                             ` Gregory Heytings
2021-11-04  6:58                                               ` Eli Zaretskii
2021-11-04  8:53                                                 ` Gregory Heytings
2021-11-04  9:15                                                   ` Eli Zaretskii
2021-11-03 19:54                                     ` Daniel Brooks
2021-11-03 20:08                                       ` Eli Zaretskii
2021-11-04  6:00                                         ` Daniel Brooks
2021-11-04  7:44                                           ` Eli Zaretskii
2021-11-04  9:14                                             ` Gregory Heytings
2021-11-04  9:45                                               ` Eli Zaretskii
2021-11-04 10:41                                                 ` Gregory Heytings
2021-11-04 11:03                                                   ` Po Lu
2021-11-04 11:27                                                     ` Gregory Heytings
2021-11-04 11:20                                                   ` Eli Zaretskii
2021-11-04 11:34                                                     ` Gregory Heytings
2021-11-04 13:25                                                       ` Eli Zaretskii
2021-11-04 14:10                                                         ` Gregory Heytings
2021-11-04 16:50                                                           ` Eli Zaretskii
2021-11-04 17:04                                                             ` Gregory Heytings
2021-11-04 19:16                                                           ` Stefan Monnier
2021-11-05 23:31                                                             ` Gregory Heytings
2021-11-06  7:25                                                               ` Eli Zaretskii
2021-11-04 19:22                                                           ` Stefan Monnier
2021-11-04 19:55                                                             ` Eli Zaretskii
2021-11-05 23:32                                                             ` Gregory Heytings
2021-11-04 19:08                                                     ` Eli Zaretskii
2021-11-04 20:00                                                       ` Eli Zaretskii
2021-11-05  2:23                                             ` Daniel Brooks [this message]
2021-11-05  3:52                                               ` Stefan Kangas
2021-11-05  5:21                                                 ` code annotations Daniel Brooks
2021-11-05  5:53                                                   ` Stefan Kangas
2021-11-05  5:23                                                 ` Unicode confusables and reordering characters considered harmful, a simple solution Daniel Brooks
2021-11-05  6:13                                                 ` Po Lu
2021-11-05  7:37                                                 ` Eli Zaretskii
2021-11-05  8:00                                                   ` Stefan Kangas
2021-11-05  8:07                                                     ` Eli Zaretskii
2021-11-05  9:58                                                       ` Stefan Kangas
2021-11-05 12:12                                                         ` Eli Zaretskii
2021-11-05 13:08                                                           ` Stefan Kangas
2021-11-05 14:19                                                             ` Eli Zaretskii
2021-11-05 23:33                                                               ` Gregory Heytings
2021-11-06  0:54                                                                 ` Daniel Brooks
2021-11-06 10:56                                                                   ` Eli Zaretskii
2021-11-06 10:48                                                                 ` Eli Zaretskii
2021-11-08 19:58                                                                   ` Gregory Heytings
2021-11-08 20:27                                                                     ` Eli Zaretskii
2021-11-08 21:59                                                                       ` Stefan Monnier
2021-11-09  3:28                                                                         ` Eli Zaretskii
2021-11-06 13:58                                                               ` Benjamin Riefenstahl
2021-11-06 15:34                                                                 ` Eli Zaretskii
2021-11-06 17:09                                                                   ` Benjamin Riefenstahl
2021-11-06 17:35                                                                     ` Eli Zaretskii
2021-11-05  8:09                                               ` tomas
2021-11-06  1:09                                                 ` Daniel Brooks
2021-11-05  8:31                                               ` Eli Zaretskii
2021-11-05  9:34                                                 ` Juri Linkov
2021-11-04 19:05                                           ` Stefan Monnier
2021-11-03 21:13                                 ` Daniel Brooks
2021-11-04  6:52                                   ` Eli Zaretskii
2021-11-02 20:18                       ` Unicode confusables and reordering characters considered harmful Tim Cross
2021-11-03  0:28                     ` Gregory Heytings
2021-11-03  1:07                       ` Stefan Monnier
2021-11-03  1:59                         ` Daniel Brooks
2021-11-03 13:35                           ` Eli Zaretskii
2021-11-03  9:59                         ` Gregory Heytings
2021-11-03 11:19                           ` Stefan Kangas
2021-11-03 11:31                             ` Gregory Heytings
2021-11-03 12:20                               ` Stefan Monnier
2021-11-03 12:41                                 ` tomas
2021-11-03 13:15                                   ` Eli Zaretskii
2021-11-03 14:46                                     ` tomas
2021-11-03 17:13                                       ` Eli Zaretskii
2021-11-03 17:34                                         ` tomas
2021-11-03 13:46                                 ` Eli Zaretskii
2021-11-03 13:45                               ` Eli Zaretskii
2021-11-03 13:44                             ` Eli Zaretskii
2021-11-03 14:29                               ` Gregory Heytings
2021-11-03 14:37                                 ` Eli Zaretskii
2021-11-03 16:01                                   ` Gregory Heytings
2021-11-03 17:44                                     ` Eli Zaretskii
2021-11-03 17:53                                       ` Gregory Heytings
2021-11-03 11:29                           ` Andreas Schwab
2021-11-03 18:47                             ` Stefan Monnier
2021-11-03 18:52                               ` Yuri Khan
2021-11-03 19:19                                 ` Stefan Monnier
2021-11-03 19:28                               ` Gregory Heytings
2021-11-03 19:32                                 ` Stefan Monnier
2021-11-03 19:41                                   ` Yuri Khan
2021-11-03 20:12                                   ` Gregory Heytings
2021-11-03 22:03                                     ` Gregory Heytings
2021-11-04  8:50                                       ` Gregory Heytings
2021-11-03 19:51                                 ` Eli Zaretskii
2021-11-03 19:30                               ` Eli Zaretskii
2021-11-03 19:34                                 ` Andreas Schwab
2021-11-03 19:54                                   ` Eli Zaretskii
2021-11-03 13:37                           ` Eli Zaretskii
2021-11-03 18:53                             ` Manuel Giraud
2021-11-03 19:36                               ` Eli Zaretskii
2021-11-03 21:15                                 ` Manuel Giraud
2021-11-04  6:56                                   ` Eli Zaretskii
2021-11-04 19:04                                     ` Eli Zaretskii
2021-11-03 13:33                         ` Eli Zaretskii
2021-11-03 13:31                       ` Eli Zaretskii
2021-11-02 19:26                   ` Stefan Kangas
2021-11-02 19:44                     ` Eli Zaretskii
2021-11-02 19:49                     ` Stefan Monnier
2021-11-02 18:16           ` Clément Pit-Claudel
2021-11-02 18:37             ` Eli Zaretskii
2021-11-02 19:17         ` Yuri Khan
2021-11-02 19:37           ` Eli Zaretskii
2021-11-02 17:24       ` [authors: default bidi-display-reordering is set to t] (was: Unicode confusables and reordering characters considered harmful) Uwe Brauer
2021-11-02 17:37         ` Eli Zaretskii
2021-11-02 14:31   ` Unicode confusables and reordering characters considered harmful Eli Zaretskii
2021-11-02 15:13     ` Uwe Brauer
2021-11-02 13:42 ` tomas
2021-11-02 14:57   ` Stefan Kangas
2021-11-02 14:30 ` Eli Zaretskii
2021-11-02 14:43 ` Clément Pit-Claudel
2021-11-03 15:07   ` Reini Urban
2021-11-03 15:43     ` Stefan Monnier
2021-11-04  7:50       ` Reini Urban
2021-11-04  8:21         ` Eli Zaretskii
2021-11-03 17:24     ` Eli Zaretskii
2021-11-02 14:57 ` Stefan Kangas
2021-11-05 18:53 ` Unicode confusables " Vasilij Schneidermann
2021-11-05 20:03   ` Eli Zaretskii
2021-11-06 11:56     ` Vasilij Schneidermann
2021-11-06 12:20       ` Eli Zaretskii
2021-11-06 13:10         ` Vasilij Schneidermann
2021-11-06 13:29           ` Eli Zaretskii
2021-11-05 21:36   ` Stefan Monnier
2021-11-10 15:47 ` Unicode confusables and reordering characters " Dmitry Gutov
2021-11-10 17:03   ` Eli Zaretskii
2021-11-10 17:15     ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k0hnqr1v.fsf@db48x.net \
    --to=db48x@db48x.net \
    --cc=cpitclaudel@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=stefan@marxist.se \
    --cc=yuri.v.khan@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.