Skip to content
Tcl Source Code History Of Ticket d1434179b5a377ec
Login

History Of Ticket d1434179b5a377ec

Artifacts Associated With Ticket d1434179b5a377ec

  1. Ticket change [b7c9496e3b] (rid 196786) by chrstphrchvz on 2021-12-12 00:52:40:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-wiki"
    4. 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>
      
    5. foundin initialized to: "8.6.12"
    6. is_private initialized to: "0"
    7. login: "chrstphrchvz"
    8. priority initialized to: "5 Medium"
    9. resolution initialized to: "None"
    10. severity initialized to: "Minor"
    11. status initialized to: "Open"
    12. submitter initialized to: "chrstphrchvz"
    13. subsystem initialized to: "44. UTF-8 Strings"
    14. title initialized to:
      avoid signed integer overflow in AppendUtfToUtfRep()
      
    15. type initialized to: "Patch"
  2. Ticket change [2fd07ff615] (rid 196861) by jan.nijtmans on 2021-12-16 21:29:37:

    1. assignee changed to: "jan.nijtmans"
    2. closedate changed to: "2459565.39557167"
    3. closer changed to: "jan.nijtmans"
    4. icomment:
      Fixed [8340945434|here]. Thanks for the report and for the patch!
      
    5. login: "jan.nijtmans"
    6. mimetype: "text/x-fossil-wiki"
    7. resolution changed to: "Fixed"
    8. status changed to: "Closed"
  3. Ticket change [66948b3d71] (rid 196862) by chrstphrchvz on 2021-12-18 12:11:46:

    1. closedate changed to: "2459567.00817203"
    2. closer changed to: "chrstphrchvz"
    3. icomment:
      Thanks for accepting this, however the description for check-in [8340945434] currently refers to [b0f84119c8] rather than this ticket, can it be revised?
      
    4. login: "chrstphrchvz"
    5. mimetype: "text/x-fossil-wiki"
  4. Ticket change [54b9c7b16d] (rid 196866) by jan.nijtmans on 2021-12-18 14:54:25:

    1. closedate changed to: "2459567.12113214"
    2. closer changed to: "jan.nijtmans"
    3. icomment: "Revised now. Thanks!"
    4. login: "jan.nijtmans"
    5. mimetype: "text/x-fossil-wiki"