Overview
| Artifact ID: | 8df4e87db56c2de30c26ed7a7253becb8c494b864bdf6e8cb63449de6e8b1bdc |
|---|---|
| Ticket: | b69e00ecf6b9c3ab7e6a99d731a6f22d82e7b7d8
Tcl does not raise an error even when it detects an invalid internal UTF-8 sequence |
| User & Date: | apnadkarni on 2025-07-16 06:40:21 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/x-markdown"
- comment changed to:
Logging this bug as a reminder to revisit Tcl internal handling of invalid strings. As an example of the broader issue, invalid UTF-8 sequences raise an error on `encoding convertfrom` but not on `encoding convertto`. ``` % encoding convertfrom utf-8 \xEF\xBF\x7F unexpected byte sequence starting at index 0: '\xEF' % binary encode hex [encoding convertto utf-8 [testbytestring \xEF\xBF\x7F]] c3afc2bf7f ``` Both the above are actually UTF8->UTF8 conversions, the first converting from standard UTF-8 to Tcl's internal UTF-8 and the latter in the other direction. (The `testbytestring` command is part of tcltest and a means to get a specific byte sequence, including invalid utf8 as above, into a `Tcl_Obj.bytes` field. Essentially it emulates `Tcl_NewStringObj` behavior from script.) `convertfrom` behaves correctly, raising an error, as that UTF-8 sequence is invalid. `convertto` on the other hand, instead of being strict and raising an error, behaves as Tcl8 despite the default strict profile. In general this behavior seems to be by design as internally there are many places where Tcl converts invalid sequences without raising an error but instead either mapping to some character, either U+FFFD, or cp1252 equivalent or assuming iso8859-1 encoding (there is no consistency in this mapping either!). While this situation only occurs when invalid data is passed in via `Tcl_NewStringObj`, `Tcl_AppendToObj` etc., I feel Tcl should raise an error (if possible, since some functions do not have an error reporting mechanism other than panicing) when this is detected. In particular, - the encoding routines should definitely raise an error under the strict policy irrespective of `convertto` or `convertfrom` - when there is no possibility of raising an error because of the API, there should be a standard character mapping used, preferably U+FFFD as neither cp1252 or iso8859-1 make any logical sense. This is a reminder to revisit this rather thorny issue of handling invalid internal string values.
- is_private changed to: "0"
- login: "apnadkarni"
- priority changed to: "5 Medium"
- private_contact changed to: "9546e9877f1a8899e25a89082561ee694e7fb402"
- resolution changed to: "None"
- severity changed to: "Important"
- status changed to: "Open"
- submitter changed to: "apnadkarni"
- subsystem changed to: "- New Builtin Commands"
- title changed to:
Tcl does not raise an error even when it detects an invalid internal UTF-8 sequence
- type changed to: "Bug"