Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2021-03-18
13:37 • Closed ticket [c574e50a3b]: CRASH: utf-2.89 in 8.5 built with TCL_UTF_MAX=4</i... artifact: 2554e5afb7 user: jan.nijtmans
2020-04-22
16:04 • Ticket [c574e50a3b]: 3 changes artifact: b14d033c6a user: jan.nijtmans
15:14 • Ticket [c574e50a3b]: 3 changes artifact: e9ddda3d51 user: jan.nijtmans
14:43 • Ticket [c574e50a3b]: 3 changes artifact: 81b2272692 user: dgp
2020-04-21
16:03 • Ticket [c574e50a3b]: 4 changes artifact: e0d2ea8e21 user: dgp
15:59
[c574e50a3b] Stop segfault in tests utf-2.[89]. Create clean test suite runs for the TCL_UTF_MAX = 4... check-in: 31e31876ef user: dgp tags: core-8-5-branch
14:59 • Ticket [c574e50a3b] CRASH: utf-2.89 in 8.5 built with TCL_UTF_MAX=4 status... artifact: 547f5d343b user: jan.nijtmans
14:52 • Ticket [c574e50a3b]: 3 changes artifact: ffbea21c14 user: dgp
14:36 • Ticket [c574e50a3b]: 3 changes artifact: 36de82a8a1 user: dgp
14:32 • Ticket [c574e50a3b]: 3 changes artifact: 9f7f8ba5bc user: dgp
14:24 • Ticket [c574e50a3b]: 3 changes artifact: 0d9f07879b user: jan.nijtmans
14:18 • Ticket [c574e50a3b]: 3 changes artifact: 6bc05abc33 user: jan.nijtmans
14:00 • Ticket [c574e50a3b]: 3 changes artifact: 24853c7934 user: dgp
2020-04-20
22:29 • Ticket [c574e50a3b]: 3 changes artifact: 3e7993b262 user: jan.nijtmans
21:01 • Ticket [c574e50a3b]: 3 changes artifact: df02fef08e user: dgp
20:37 • Ticket [c574e50a3b]: 3 changes artifact: 2bdacbdff7 user: dgp
19:59 • Ticket [c574e50a3b]: 3 changes artifact: 6f972059f1 user: dgp
15:41 • Ticket [c574e50a3b]: 3 changes artifact: 4271cdabe1 user: dgp
15:18 • Ticket [c574e50a3b]: 3 changes artifact: 43bbb4d4f0 user: dgp
15:18 • Ticket [c574e50a3b]: 3 changes artifact: e439b88bef user: jan.nijtmans
15:14 • Ticket [c574e50a3b]: 3 changes artifact: f4265e3d25 user: dgp
14:56 • Ticket [c574e50a3b]: 3 changes artifact: 7fd9e14675 user: dgp
14:18 • Ticket [c574e50a3b]: 3 changes artifact: a586e633b5 user: dgp
08:01 • Ticket [c574e50a3b]: 3 changes artifact: a9e56e2554 user: jan.nijtmans
07:37 • Ticket [c574e50a3b]: 3 changes artifact: 5dd34dddf9 user: dgp
2020-04-18
15:26 • Ticket [c574e50a3b]: 3 changes artifact: 6f9556e2aa user: dgp
14:54 • Ticket [c574e50a3b]: 3 changes artifact: 02ca150ff1 user: dgp
14:20 • Ticket [c574e50a3b]: 3 changes artifact: d9e13784fa user: dgp
14:17 • Open ticket [c574e50a3b]. artifact: 55399bb9cf user: dgp
14:02 • Closed ticket [c574e50a3b]. artifact: a5b309ea87 user: dgp
13:47
Fix [c574e50a3b30e76f]: CRASH: utf-2.[89] in 8.5 built with TCL_UTF_MAX=4 check-in: dda19888bd user: jan.nijtmans tags: bug-c574e50a3b
12:31 • Ticket [c574e50a3b] CRASH: utf-2.89 in 8.5 built with TCL_UTF_MAX=4 status... artifact: 87b135b8bb user: jan.nijtmans
00:00 • Ticket [c574e50a3b]: 3 changes artifact: 7bcab85b94 user: dgp
2020-04-17
21:12 • New ticket [c574e50a3b]. artifact: ccf02b0407 user: dgp

CRASH: utf-2.[89] in 8.5 built with TCL_UTF_MAX=4

Closed / Fixedc574e50a3b30e76f6c57bdcf27e043bcd030dbdaCreated 7 years agoUpdated 6 years ago
Descriptionplain2020-04-17 21:12:10
utf.test
---- utf-2.8 start
Test file error: child killed: segmentation violation
Referenced by1
  • 31e31876ef[c574e50a3b] Stop segfault in tests utf-2.[89]. Create clean test suite runs for the TCL_UTF_MAX = 4, 6 builds. check-in2020-04-21 15:59:47
dgpplain2020-04-18 00:00:54
This trouble with a TCL_UTF_MAX=4 build arrived in

https://core.tcl-lang.org/tcl/info/ee9f293421a3ce09

Didn't have the test then to expose it.
jan.nijtmanswiki2020-04-18 12:31:01

Indeed. Backported too much from tclUtf.c, parts that were not appropriate fro 8.5. Will fix

dgpplain2020-04-18 14:02:39
Thanks. The other fix is dangling out there on a closed branch, but I like
this answer better.

Issue was the same initialization woes the other branches have been through.
dgpplain2020-04-18 14:17:52
Declared victory too soon. Now for any build with TCL_UTF_MAX > 3
the tip of core-8-5-branch blocks in the tests chan-io-6.45 and io-6.45
and the test encoding-16.1 fails:

==== encoding-16.1 UnicodeToUtfProc FAILED
==== Contents of test case:

    set val [encoding convertfrom unicode NN]
    list $val [format %x [scan $val %c]]

---- Test generated error; Return code was: 1
---- Return code should have been one of: 0 2
---- errorInfo: expected integer but got ""
    while executing
"format %x [scan $val %c]"
    ("uplevel" body line 3)
    invoked from within
"uplevel 1 $script"
---- errorCode: TCL VALUE NUMBER
==== encoding-16.1 FAILED
dgpplain2020-04-18 14:20:33
Also

==== source-7.2 source -encoding test FAILED
==== Contents of test case:

    set x unset
    source -encoding unicode $sourcefile
    set x

---- Test generated error; Return code was: 1
---- Return code should have been one of: 0 2
---- errorInfo: invalid command name "��������������������"
    while executing
"��������������������"
    (file "/Users/dgp/fossil/tcl8.5/tum4/source.file" line 1)
    invoked from within
"source -encoding unicode $sourcefile"
    ("uplevel" body line 3)
    invoked from within
"uplevel 1 $script"
---- errorCode: NONE
==== source-7.2 FAILED
dgpplain2020-04-18 14:54:56
Problem appears to be an issue over whether sizeof(Tcl_UniChar) is 2 or 4.

I think the answer is that in the 8.5 branch it should never be anything other than 2.
dgpplain2020-04-18 15:26:40
There's still trouble here. Moving the efforts to a bug-fix branch.
dgpplain2020-04-20 07:37:53
Found and backported the fixes for a TCL_UTF_MAX=6 build where
we use UCS-4 internally.

Still need to resolve what TCL_UTF_MAX=4 is going to mean on this
branch.  If Tcl_UniChar is UCS-2 and no surrogates, we have no place
to store codepoints beyond U+FFFF, so do we convert all 4-byte
sequences to the replacement character? Do we actively prevent
generation of 4-byte sequences? (as in [format %c 0x10000])
jan.nijtmansplain2020-04-20 08:01:17
> Still need to resolve what TCL_UTF_MAX=4 is going to mean on this branch

Yeah, I'm thinking on that too. Originally, it meant: Use "unsigned int" 
for Tcl_UniChar, and support code ponts >0xFFFF.  But with commit [98f64c277b5e6b2f], I tried to backport some of TIP 386 to the 8.5 branch.
I regret that commit now. So if we can just undo [98f64c277b5e6b2f], and threat all values of TCL_UTF_MAX>3 to mean the same? That would make our work a lot simpler.

Since TCL_UTF_MAX > 3 is - and always have been - UNSUPPORTED, it's up to use what we do with it. No one uses it, as far as I know, and a lot of test-case fail.
dgpplain2020-04-20 14:18:37
Here are the available configurations that make sense (IMO):

[A] Only 3-byte sequences supported. Internal store as UCS-2.

[B] All sequences supported. Internal store as UCS-4.

[C] All sequences supported. Internal store as UTF-16.

[D] All sequences supported, Internal store as UCS-2. Convert all sequences representing U+10000 and higher to U+FFFD (replacement character).

Is there anything else worth thinking about?
dgpplain2020-04-20 14:56:10
With that vocabulary, we've had a history of the 8.5 releases through 8.5.19:

UTF_MAX=3: [A]
UTF_MAX=4: unusable FSS-UTF remnants
UTF_MAX=6: unusable FSS-UTF remnants

In the long time since 8.5.19, the unsupported configurations have been improved,
and I think we should aim for:

UTF_MAX=3: [A]
UTF_MAX=4: [B]
UTF_MAX=6: [B]
dgpplain2020-04-20 15:14:30
As I read TIP 542, we expect 8.7 to offer:

UTF_MAX=3:  [C] (default)
UTF_MAX=4:  [B]
UTF_MAX=6:  [B]
jan.nijtmanswiki2020-04-20 15:18:00

Well, about your last 2 remarks: I agree, that's exactly what I'm trying to say.

dgpplain2020-04-20 15:18:36
I don't think we've fully voted and spec'd the 9.0 plan yet, but it looks like we're aiming for:

UTF_MAX=3:  ???? (will this even be offered?)
UTF_MAX=4: [B]
UTF_MAX=6: [B] (again will this option be retained?)
dgpplain2020-04-20 15:41:46
The 8.6 history and plan is messier. Start with releases 8.6.0 - 8.6.4:

UTF_MAX=3: [A]
UTF_MAX=4: unusable FSS-UTF remnants
UTF_MAX=6: unusable FSS-UTF remnants
dgpplain2020-04-20 19:59:26
Checkin 

https://core.tcl-lang.org/tcl/info/e2278643dc

first tried to do something better, including a first stab at some use of
surrogates, but it kept in place decoding of 5- and 6-byte sequences
(for TCL_UTF_MAX == 6) and it got decoding of 4-byte sequences
(when TCL_UTF_MAX == 4) completely wrong, discarding the high bits.

% package present Tcl                  
8.6.5
% format %X [scan [encoding convertfrom identity \xF0\x9F\x92\xA9] %c]
F4A9

(Should be 1F4A9)

There are hints that the 8.6.5 release was starting to aim for

UTF_MAX=3: [A]
UTF_MAX=4: [C]
UTF_MAX=6: [B]

but it's best to still think of the unsupported configurations as unusable.
dgpplain2020-04-20 20:37:16
Release Tcl 8.6.6 is the same. Notably a failure of utf-2.12 in a 
(TCL_UTF_MAX = 6) build demonstrates it is still respecting 5-byte
sequences. Mostly just as broken as 8.6.5 was.

The default build (TCL_UTF_MAX = 3) continues to implement mode [A].
dgpplain2020-04-20 21:01:16
In release 8.6.7 the bug of accepting overlong sequences was fixed, and as
a side effect, the (TCL_UTF_MAX = 4) build broke in a new way.

% package present Tcl 
8.6.7
% format %X [scan [encoding convertfrom identity \xF0\x9F\x92\xA9] %c]
F0

By now though, it is reasonable to label the other two builds.

UTF_MAX=3: [A]
...
UTF_MAX=6: [B]
jan.nijtmanswiki2020-04-20 22:29:29

> Is there anything else worth thinking about?

One more:

[E] Only 3-byte sequences supported. Internal store as UTF-16.

This is almost the same as [A], the difference is in the translation to the internal store. [A] lets every invalid 4-byte UTF-8 sequence occupy 4 locations in the store, one for every byte (not really sensible ...). [E] stores invalid 4-byte UTF-8 sequence in 2 locations, namely the two surrogates. The translation from internal store back to UTF-8 is identical to [A]. For valid 1-, 2- or 3-byte UTF-8 sequences [E] behaves exactly the same as [A].

dgpplain2020-04-21 14:00:28
Just to clarify my understanding.

[A] is 4-bytes in, 8 bytes out.

Either loses/corrupts unsupported characters, or demands special (also unsupported) interventions to dig them back out.

[E] is 4-bytes in, 6 bytes out.

Violates standards, but allows for recovery of the unsupported characters.

[E] also has the indexing incompatibility issues that come along with UTF-16
getting exposed to interfaces.
jan.nijtmansplain2020-04-21 14:18:21
> [E] also has the indexing incompatibility issues that come along with UTF-16
> getting exposed to interfaces.

Not if the surrogate pairs are counted a 2 characters. So the 4-byte (illegal sequences) must also be counted as 2 characters. And Tcl_UtfNext()/Tcl_UtfPrev() should be needed twice to jump over it. I did it ;-)
jan.nijtmanswiki2020-04-21 14:24:17

The difference between [A] and [E] is impossible to detect at script level, you need things like the "identiy" encoding or "testbytestring" to detect the difference.

dgpplain2020-04-21 14:32:55
One more I'll add to the menu.

[F] All valid sequences accepted. ALL INVALID SEQUENCES REJECTED (error or REPLACEMENT). Internal store UCS-4.

Something I think we should at least consider for Tcl 9.
dgpplain2020-04-21 14:36:23
"impossible to detect at script level"

I get what you mean. Supported/recommended script commands that generate strings will not generate anything that reveals the difference.

The handling of data received from channels would reveal the difference.
dgpplain2020-04-21 14:52:56
The blocking and failing tests are illustrations of existing tickets
[1004065] and [1122671], recording that the encoding machinery hardcodes
assumptions in multiple places that sizeof(Tcl_UniChar) == 2.

Closing the segfault bug fix should not be hostage to fixing those old bugs.
jan.nijtmansplain2020-04-21 14:59:37
Example:
<pre>
$ tclsh8.6
% puts stdout \uD800\uDC00
𐀀
% puts stdout [encoding convertfrom utf-8 \xF0\x90\x80\x80]
𐀀
% string length [encoding convertfrom utf-8 \xF0\x90\x80\x80]
2
</pre>

Even though in Tcl 8.6, 4-byte sequences are illegal, the Utf2Utf encoder translates those to 2 surrogates, and everything behaves as expected. That's a better fallback than splitting it into 4 characters
dgpplain2020-04-21 16:03:27
The bug that opened this ticket is now fixed. Leaving the ticket open for the value of other comments for now.
dgpplain2020-04-22 14:43:31
The constraint "ucs2" is distinct from "compat85" and needs to be restored.

"ucs2" might be a bad name for it. We can change that, but I need a way
to directly determine whether (sizeof(Tcl_UniChar) == 2) and nothing else.

The "compat85" constraint tests whether Tcl has no way to internally
store codepoints > U+FFFF. That is not the same thing.

In a default build of Tcl 8.7, the "compat85" constraint should be false,
but the "ucs2" constraint should be true.
jan.nijtmanswiki2020-04-22 15:14:41

> The "compat85" constraint tests whether Tcl has no way to internally > store codepoints > U+FFFF. That is not the same thing.

Since the UCS2 encoding cannot store codepoints > U+FFFF, I liked that name very much for this purpose. It's different from sizeof(Tcl_UniChar) == 2, since UTF16 has sizeof(Tcl_UniChar) == 2 too.

Would you agree with using another constraint-name for the sizeof(Tcl_UniChar) check?

Sorry for kidnapping your "ucs2" name ...;-)

jan.nijtmanswiki2020-04-22 16:04:04

Another possible solution: [b85215dae6e78c1b]. Let's see - tomorrow - what Travis thinks of it.

jan.nijtmanswiki2021-03-18 13:37:03

Merged to core-8-5-branch in [ed551cd16c]

Log in (anonymous is fine) to add a comment.