Artifacts Associated With Ticket 0f1ddc0df7fb734c
Ticket change [574953e3f1] (rid 220655) by anonymous on 2023-11-27 15:57:26:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-markdown"
- comment initialized to:
If executing the diff program with command exec on two files with different encodings, the output of diff cannot be read with Tcl9. The following error message is generated: invalid or incomplete multibyte or wide character The problem occurres using tkdiff and can be reproduced by the following script: <code> puts "Using Tcl [info patchlevel]" set cmd "diff iso8859.txt utf8.txt" catch {eval ::exec $cmd} ret puts "ret=$ret" </code> Test files will be attached. Paul - foundin initialized to: "9.0"
- is_private initialized to: "0"
- login: "anonymous"
- priority initialized to: "5 Medium"
- private_contact initialized to: "2e499ca9e0149983f6f63603feedc5b33bc05f5e"
- resolution initialized to: "None"
- severity initialized to: "Important"
- status initialized to: "Open"
- submitter initialized to: "anonymous"
- subsystem initialized to: "16. Commands A-H"
- title initialized to: "exec does not handle encoding"
- type initialized to: "Bug"
Add attachment "iso8859.txt" [07bb169e17] (rid 220656) by anonymous on 2023-11-27 15:58:06.
Add attachment "utf8.txt" [7209f5bfc6] (rid 220657) by anonymous on 2023-11-27 15:58:21.
Ticket change [314740cccf] (rid 220659) by dkf on 2023-11-27 16:47:26:
- icomment:
The `exec` command is notably very simple-minded in that it uses the system encoding for everything including for the encoding of channels used to communicate with the subprocess, and it always assumes that output is readable text in that encoding. *It very much is known that this isn't always so!* However, "fixing" this tends to make `exec` much harder to use in the simple cases. The ***workaround*** is to use a pipeline, perhaps like this: ``` set f [open |$cmd rb] # Binary output can be any byte sequence; no encoding problems possible set output [read $f] catch {close $f} err ``` Since you have access to the channel above (unlike inside `exec` which handles all of that internally) you can configure it any way you want to handle the input or output you expect. (It also makes it easier to capture stderr of the pipeline without losing stdout, etc.) Note that both `exec` and `open |...` are wrappers around the same subsystem. - login: "dkf"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [a47170cc4f] (rid 220663) by pointsman on 2023-11-27 20:07:27:
- icomment:
Perhaps the better workaround for the given example would be: <code> set fd [open |$cmd] fconfigure $fd -profile replace puts "ret:[read $fd]" </code> While it is true that exec is simple-minded wrt to the encoding of the stdin, stdout (and stderr) of the started process the core problem here are the changes in the I/O system of Tcl 9, especially TIP 657. Please note that this is an improvement. With Tcl 8.6 the code example provided by Paul show a wrong result without a chance that the programm / programmer is able to notice. But perhaps it would be better if exec would open the channels always with -profile replace. TIP 657 already has the exception of the glob command (and access to the env array). This would be another one, for reasons.
- login: "pointsman"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [42f2b5a501] (rid 220665) by apnadkarni on 2023-11-28 03:01:55:
- icomment:
I also share Rolf's opinion that commands where there is no option to configure the encoding profile used by the command should use the replace profile. This was already the case in 657 for glob, env as Rob mentions, and I would argue should be the case for exec as well. As an aside, I would think the same would apply to *arguments* passed to exec as well as command line passed to tclsh (argv, argv0) though that may be a more minor issue and not worth bothering over.
- login: "apnadkarni"
- mimetype: "text/plain"
- icomment:
Ticket change [c5d7963d8e] (rid 220702) by jan.nijtmans on 2023-12-01 11:48:21:
- icomment:
> This was already the case in 657 for glob, env as Rob mentions glob, env currently still uses the "tcl8" profile, since no-one decided to change that. Command line arguments to tclsh/wish still use "tcl8" profile as well.
- login: "jan.nijtmans"
- mimetype: "text/plain"
- icomment:
Ticket change [7771053db5] (rid 220706) by jan.nijtmans on 2023-12-01 12:03:40:
- icomment:
If we decide that the best profile for env/glob/argv handling is "replace", we could also make one step further and change the default flag for Tcl_UtfToExternalDString/Tcl_ExternalToUtfDString. That's easier than replace all such calls with the *Ex() alternative, specifying TCL_ENCODING_PROFILE_REPLACE separately everywhere. How do we think about: [0d84761f9fecedd4|this]?
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [ad32f5c0ad] (rid 220712) by oehhar on 2023-12-01 16:40:51:
- icomment:
Hi Jan, thanks, that you jump into the boat. Things move, if this happens. My opinion: * In TCL9, any encoding profile default should change to replace, if it is tcl8. So, I agree with the change. * I don't think, this handles the initial issue. The exec profile must be set somewhere else to strict. Take care, Harald
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
- icomment:
Ticket change [bc27692759] (rid 220771) by apnadkarni on 2023-12-05 14:06:31:
- icomment:
WIP in [apn-bug-0f1ddc0df7]. This intentionally fixes only exec to use the replace profile. In particular, open is unchanged (strict default) as the -profile option can be used there to if necessary. Still WIP because stderr output behaves as if strict profile is in use.
- login: "apnadkarni"
- mimetype: "text/x-fossil-plain"
- icomment:
Ticket change [9055ee1f42] (rid 220787) by apnadkarni on 2023-12-05 17:12:52:
- icomment:
Code ready for review, will merge if no objections in a day or two. Paul's sample test output is now ``` % catch {eval ::exec $cmd} ret 1 % puts "ret=$ret" ret=2c2 < ���� --- > äöüß child process exited abnormally ``` which I think is correct (the catch raises exception because of diff output as expected) - login: "apnadkarni"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [0102c656fd] (rid 220804) by anonymous on 2023-12-05 21:56:21:
- icomment:
Works fine with the test script and inside tkdiff. Paul
- login: "anonymous"
- mimetype: "text/plain"
- icomment:
Ticket change [089f4a2129] (rid 220846) by apnadkarni on 2023-12-07 03:11:33:
- icomment: "Fixed in [43d35b1d8b]."
- login: "apnadkarni"
- mimetype: "text/x-fossil-plain"
Ticket change [715992274c] (rid 220847) by apnadkarni on 2023-12-07 03:11:57:
- closedate changed to: "2460285.63330497"
- closer changed to: "apnadkarni"
- login: "apnadkarni"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"
Ticket change [d15070dd25] (rid 220848) by oehhar on 2023-12-07 08:57:26:
- closedate changed to: "2460285.87322318"
- closer changed to: "oehhar"
- icomment:
I want to thank Ashok for this work. We had that open for TCL 9.0 in the weekly wrap-up and Ashok volunteered to look into this. We should always remember, that behind each commit, there are hours of work. Thank you all, guys, Harald
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
Ticket change [5731532058] (rid 225703) by pooryorick on 2024-05-13 09:08:00:
- closer changed to: "nobody"
- icomment:
I've reopened this issue and changed the resolution to "wont fix" in order to further discuss this. "replace" is a minefield, and saving unsuspecting scripts from stepping on a mine when using <code>exec</code> was a big benefit of the decision to use "strict" by default. glob was only excluded from TIP 657 because no one had the wherewithal to fix it at the time of that TIP. Bad data due to bad encoding is a big problem. Bad data cause problems down the line after it's too late to do anything about it, especially when they get into persistent storage and are processed much later. It is quite common for naive scripts to use <code>exec</code> to obtain binary data. In this case the earlier there is a notable error the better, as it allows the author to correct the script. This case is much more common than the mixed-encoding problem raised in the current issue. For programs like the diff program mentioned in this issue that are just doing their job in some encoding-agnostic way, <code>open</code> can always be used instead. Therefore, there is no real need to strip <code>exec</code> of its strict behaviour. I propose that <code>exec</code> retain its newfound strict powers, and that Tcl developers focus on adding further knobs to exec if that is deemed worthwhile.
- login: "pooryorick"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Wont Fix"
- status changed to: "Open"
Ticket change [7002ee1761] (rid 225705) by jan.nijtmans on 2024-05-13 10:06:24:
- icomment:
> I propose that exec retain its newfound strict powers I'll discuss this with Harald, Brian, Steve and Ashok. My guess is that your proposal will not be accepted for 9.0b2.
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [01074756ca] (rid 225706) by jan.nijtmans on 2024-05-13 10:08:53:
- icomment: "..... and Rolf, of course ...."
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
Ticket change [291f380f7f] (rid 225716) by oehhar on 2024-05-13 12:28:03:
- closedate changed to: "2460444.01948392"
- closer changed to: "oehhar"
- icomment:
Nathan, sorry. The process for fixing was done and accepted by the author of the ticket. The reason for this are many voices fearing incompatibilites and code breakage due to errors thrown, were there were no errors before. The drivers for this are people maintaining a lot of code within large organizations like Don Porter. It was also made clear, that exec has limitations and open could be used, if the codepage profile is important. I can understand your agument and I also was convinced of "strict anywhere". But this has changed as a community view. As a consequence, I close the ticket and set the status to "fixed". Thank you for your comprehension, Harald
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"
- username: "oehhar"
Ticket change [f26c12be40] (rid 225722) by oehhar on 2024-05-13 13:10:13:
- closedate changed to: "2460444.04876841"
- login: "oehhar"
- mimetype: "text/plain"
- title changed to:
exec fails on encoding errors present in the output of the executed command
Ticket change [58da19d504] (rid 225723) by oehhar on 2024-05-13 13:11:22:
- closedate changed to: "2460444.04956326"
- icomment:
Paul, I allowed me to change the title of the ticket. I hope this is ok. Take care, Harald
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"