Artifacts Associated With Ticket f5eadcbf9a
Ticket change [92ef8facf8] (rid 213858) by pooryorick on 2023-04-25 20:26:02:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
In various locations in the source code uninitialized data is passed to Tcl_UniCharToUtf() via its *buf argument. In addition to holding the result of Tcl_UniCharToUtf(), since [e2278643dc330026] in 2015 *buf also serves to maintain the state of an ongoing surrogate character transformation, and random data in the uninitialized storage can cause Tcl_UniCharToUtf() to corrupt data.
- is_private initialized to: "0"
- login: "pooryorick"
- priority initialized to: "5 Medium"
- private_contact initialized to: "2b2275eab1118e1fab0016cf1c5702893c6af86c"
- resolution initialized to: "None"
- severity initialized to: "Severe"
- status initialized to: "Open"
- submitter initialized to: "pooryorick"
- subsystem initialized to: "- New Builtin Commands"
- title initialized to:
passing pointer to uninitialized memory leads Tcl_UniCharToUtf() to corrupt data
- type initialized to: "Bug"
Ticket change [e4991f1bd6] (rid 213865) by pooryorick on 2023-04-25 20:36:50:
- comment changed to:
In various locations in the source code uninitialized data is passed to <code>Tcl_UniCharToUtf()</code> via its <code>*buf</code> argument. In addition to holding the result of <code>Tcl_UniCharToUtf()</code>, since [e2278643dc330026] in 2015 <code>*buf</code> also serves to maintain the state of an ongoing surrogate character transformation, and random data in the uninitialized storage can cause <code>Tcl_UniCharToUtf()</code> to corrupt data.
- icomment: "Fixed in [f5eadcbf9a6b1b4c]."
- login: "pooryorick"
- mimetype: "text/x-fossil-wiki"
- status changed to: "Pending"
- comment changed to:
Ticket change [3fd844f6af] (rid 213866) by pooryorick on 2023-04-25 20:39:18:
- icomment:
A better fix would be to isolate the stateful data so that it isn't necessary to initialize the entire buffer, and an even better fix would be to use a proper structure to hold both the buffer and other pertinent information.
- login: "pooryorick"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- icomment:
Ticket change [799f8dfc20] (rid 213867) by jan.nijtmans on 2023-04-25 20:50:50:
- icomment:
This is a non-issue. In Tcl 9.0 with TCL_UTF_MAX=4, Tcl_UniCharToUtf() doesn't combine surrogates any more. You could put #ifdef's "TCL_UTF_MAX < 4" around it, otherwise this patch only costs performance without any benefit. Please don't do that (asking nicely)
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [bee6417cc4] (rid 213868) by jan.nijtmans on 2023-04-25 20:58:50:
- icomment:
Example of a much better bug-report, with testcase: [95e287b956].
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- severity changed to: "Minor"
- icomment:
Ticket change [e3104d5d36] (rid 213870) by pooryorick on 2023-04-26 02:36:54:
- icomment:
This is not a non-issue. Commit [a61fef8429dfff4b] was recently moved off trunk due to the fact that it caused test format-2.19 to fail under a build of TCL_UTF_MAX = 3. This bug is the cause of that failure. In every spot except one "TCL_UTF_MAX < 4" would not be incorrect. I considered adding those, but I think Tcl_UniCharToUtf() is an example of the type of coding that there should be zero tolerance for, as smuggling flags and state into existing argument turns the code into a booby trap for future developers. See [https://web.stanford.edu/~ouster/cgi-bin/cs190-winter18/lecture.php?topic=complexity|The Nature of Complexity] by Jon Ousterhout. Instead, the signature of Tcl_UniCharToUtf() should be changed to explicitly support the new functionality. Also, TCL_UTF_MAX = 3 should be removed from trunk and from Tcl 9. It no longer serves any purpose, and is responsible for at least this bug. For whatever reason, valgrind is not picking up on this issue. Jan, you won't be able to create a test case for this issue, yet it is real. After this is fixed and my commit mentioned above is reapplied to trunk, format-2.19 will be one canary for the issue.
- login: "pooryorick"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [981f63f81f] (rid 213871) by pooryorick on 2023-04-26 02:44:59:
- icomment:
The Tcl code base has suffered a growing complexity problem in recent years, This report is just one symptom of the larger issue. Practices like the use of novel techniques to overload function signatures, the proliferation of macros that create different code bases during preprocessing, and other contortions in the name of preserving backwards compatibility should be curtailed.
- login: "pooryorick"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [fdff598bc8] (rid 213873) by pooryorick on 2023-04-26 03:28:24:
- icomment:
I started to enclose the calls to memset in a "TCL_UTF_MAX < 4" block as requested by Jan, but then decided against it. This is bad practice that makes the code more brittle for future developers. The cost of memset should be born until the code can be improved.
- login: "pooryorick"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [389fbe0bc9] (rid 213886) by jan.nijtmans on 2023-04-26 12:25:21:
- icomment:
This doesn't give much confidence that you tested your stuff: [https://github.com/tcltk/tcl/actions/runs/4806142861/jobs/8553302123] <pre> utfext.test ==== Tcl_ExternalToUtf-ascii-414243-start-end Tcl_ExternalToUtf - ascii - 414243 - start end FAILED ==== Contents of test case: testencoding Tcl_ExternalToUtf ascii ABC {start end} {} 40 ---- Result was: ok {} ABC\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF ---- Result should have been (exact matching): ok {} ABC\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF ==== Tcl_ExternalToUtf-ascii-414243-start-end FAILED ... Tests ended at Wed Apr 26 07:50:29 UTC 2023 all.tcl: Total 56303 Passed 50591 Skipped 5704 Failed 8 </pre> - login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [c61c0041b7] (rid 213887) by pooryorick on 2023-04-26 13:00:31:
- icomment:
Jan, first you get defensive and call this a non-issue, then you spam the ticket with test results from a work-in-progress branch in an attempt to distrct from the real issue: Random data in uninitialized memory are causing the "format-2.19" test to fail under a build of the pyk-Tcl_AppendObjToObj branch configured with "TCL_UTF_MAX = 3"? Did you even notice that those failing tests hard-coded a dependence on uninitialized data, and just need to be adjusted for the fact that the memory area is now initialized? I'm not in favor of the memset() solution. I'm in favor of deleting a whole bunch of "TCL_UTF_MAX = 3" code.
- login: "pooryorick"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [a3361a4d4a] (rid 213974) by pooryorick on 2023-04-27 20:43:36:
- assignee changed to: "pooryorick"
- icomment:
Rather than adjusting those tests I've modified the memset() calls to fill 0xff instead of 0. Fix now applied to trunk [480c856482].
- login: "pooryorick"
- mimetype: "text/x-fossil-wiki"
Ticket change [e3649dc9a2] (rid 214428) by pooryorick on 2023-05-03 10:40:33:
- closedate changed to: "2460067.94483358"
- closer changed to: "pooryorick"
- login: "pooryorick"
- mimetype: "text/plain"
- status changed to: "Closed"