Artifacts Associated With Ticket d1434179b5
Ticket change [b7c9496e3b] (rid 196786) by chrstphrchvz on 2021-12-12 00:52:40:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
<tt>AppendUtfToUtfRep()</tt> aborts if there was signed integer overflow when <tt>int newLength</tt> was computed, but this relies on undefined behavior (as Tcl normally isn’t compiled with e.g. <tt>-fwrapv</tt>). [https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#available-checks|UBSan (<tt>-fsanitize=signed-integer-overflow</tt>)] complaint: <blockquote><pre> % set 1GiB_string [string repeat { } [expr {1 << 30}]] % puts [string bytelength $1GiB_string] 1073741824 % set 2GiB_string [string cat $1GiB_string $1GiB_string] <span style="font-weight:bold">tcl/generic/tclStringObj.c:1725:26: <span style="color:red">runtime error:</span> signed integer overflow: 1073741824 + 1073741824 cannot be represented in type 'int'</span> SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior tcl/generic/tclStringObj.c:1725:26 in max size for a Tcl value (2147483647 bytes) exceeded </pre> (<tt>tclsh8.6</tt> aborted) </blockquote> The overflow check should instead be done before <tt>newLength</tt> is computed (as similarly done elsewhere in Tcl 8.6): <pre> diff --git generic/tclStringObj.c generic/tclStringObj.c index 22e025c9b..7c04385f4 100644 --- generic/tclStringObj.c +++ generic/tclStringObj.c @@ -1722,10 +1722,10 @@ AppendUtfToUtfRep( objPtr->length = 0; } oldLength = objPtr->length; <span style="color:green">+ if (numBytes > INT_MAX - oldLength) {</span> <span style="color:green">+ Tcl_Panic("max size for a Tcl value (%d bytes) exceeded", INT_MAX);</span> <span style="color:green">+ }</span> newLength = numBytes + oldLength; <span style="color:red">- if (newLength < 0) {</span> <span style="color:red">- Tcl_Panic("max size for a Tcl value (%d bytes) exceeded", INT_MAX);</span> <span style="color:red">- }</span> stringPtr = GET_STRING(objPtr); if (newLength > stringPtr->allocated) { </pre> - 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: "44. UTF-8 Strings"
- title initialized to:
avoid signed integer overflow in AppendUtfToUtfRep()
- type initialized to: "Patch"
Ticket change [2fd07ff615] (rid 196861) by jan.nijtmans on 2021-12-16 21:29:37:
- assignee changed to: "jan.nijtmans"
- closedate changed to: "2459565.39557167"
- closer changed to: "jan.nijtmans"
- icomment:
Fixed [8340945434|here]. Thanks for the report and for the patch!
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"
Ticket change [66948b3d71] (rid 196862) by chrstphrchvz on 2021-12-18 12:11:46:
- closedate changed to: "2459567.00817203"
- closer changed to: "chrstphrchvz"
- icomment:
Thanks for accepting this, however the description for check-in [8340945434] currently refers to [b0f84119c8] rather than this ticket, can it be revised?
- login: "chrstphrchvz"
- mimetype: "text/x-fossil-wiki"
Ticket change [54b9c7b16d] (rid 196866) by jan.nijtmans on 2021-12-18 14:54:25:
- closedate changed to: "2459567.12113214"
- closer changed to: "jan.nijtmans"
- icomment: "Revised now. Thanks!"
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"