Artifacts Associated With Ticket 1bd796d9c2915891
Ticket change [85a32ab58a] (rid 200074) by chrstphrchvz on 2022-04-11 21:27:55:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
There are multiple instances of signed integer overflow in <tt>Tcl_DString</tt> functions. But I am not merely proposing that the overflowing operations be performed as <tt>unsigned int</tt>, because there would still be problematic behavior, such as an infinite loop in <tt>Tcl_ExternalToUtfDString()</tt> during <tt>encoding convertfrom …</tt> in this example (assuming it doesn’t first panic due to insufficient memory): <pre> set f [open /dev/zero [list RDONLY BINARY]] fconfigure $f -buffersize [expr {2**20}] puts [time {set z [read $f [expr {2**30-1}]]} 1] puts [::tcl::unsupported::representation $z] puts [time {set a [string cat [encoding convertto ascii {a}] $z]} 1] puts [::tcl::unsupported::representation $a] puts [time {set s [encoding convertfrom ascii $a]} 1] puts [::tcl::unsupported::representation $s] </pre> The infinite loop is due to never being able to grow the destination string large enough for <tt>TableToUtfProc()</tt> to stop returning <tt>TCL_CONVERT_NOSPACE</tt>. There is also overflow wraparound which causes the destination string to be unexpectedly truncated, losing part of the result. If these sorts of issues are to be resolved (rather than considered won’t-fix for Tcl 8), it seems there would first need to be a decision made on what the intended behaviors are; I’m not sure if I can identify all of them. But this would include deciding what the maximum allowed <tt>length</tt> should be: it seems possible to support <tt>length == INT_MAX</tt> by having Tcl internally treat <tt>spaceAvl</tt> as if it were <tt>unsigned int</tt> (since clients aren’t supposed to use this field anyway) and accommodate <tt>spaceAvl == INT_MAX + 1u</tt>; alternatively, it seems possible to only support up to <tt>length == INT_MAX - 1</tt> through additional <tt>Tcl_Panic()</tt> usage (since the affected functions cannot indicate an error to the caller, and panicking during these functions is already possible when <tt>ckalloc()</tt> or <tt>ckrealloc()</tt> fail). It would also include deciding what to do when a <tt>Tcl_DString</tt> of maximum possible <tt>length</tt> still isn’t large enough to accommodate a result (panicking again seems like an option, since that can already happen due to memory allocation failure). - foundin initialized to: "8.6.12"
- is_private initialized to: "0"
- login: "chrstphrchvz"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "chrstphrchvz"
- subsystem initialized to: "11. Conversions from String"
- title initialized to: "multiple issues in Tcl_DString functions"
- type initialized to: "Bug"
Ticket change [b4d696d987] (rid 200075) by chrstphrchvz on 2022-04-11 21:28:08:
- icomment:
On panicking: I personally want to avoid encouraging further <tt>Tcl_Panic()</tt> proliferation, because some situations where Tcl panics instead of generating an error seem to be only because panicking was much easier than implementing Tcl error handling. Unfortunately the lack of error handling is already baked into the <tt>Tcl_DString</tt> API.
- login: "chrstphrchvz"
- mimetype: "text/x-fossil-wiki"
- icomment: