Skip to content
Tcl Source Code History Of Ticket ac6792195d
Login

History Of Ticket ac6792195d

Artifacts Associated With Ticket ac6792195d

  1. Ticket change [111d158fa3] (rid 196785) by chrstphrchvz on 2021-12-11 06:10:09:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-wiki"
    4. comment initialized to:
      In <tt>BinaryEncodeUu()</tt> (generic/tclBinary.c), data to encode is bitwise-ORed into <tt>int n</tt> and typically is eventually left-shifted out, causing signed integer overflow which is undefined behavior. [https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#available-checks|UBSan (<tt>-fsanitize=shift-base</tt>)] complaint:
      
      <blockquote><pre>
      $ ./tcltest ../tests/binary.test
      <span style="font-weight:bold">tcl/generic/tclBinary.c:2700:8: <span style="color:red">runtime error:</span> left shift of 1633837921 by 8 places cannot be represented in type 'int'</span>
      SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior tcl/generic/tclBinary.c:2700:8 in 
      <span style="font-weight:bold">tcl/generic/tclBinary.c:2707:8: <span style="color:red">runtime error:</span> left shift of 1667326563 by 8 places cannot be represented in type 'int'</span>
      SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior tcl/generic/tclBinary.c:2707:8 in 
      binary.test:	Total	717	Passed	640	Skipped	77	Failed	0
      Number of tests skipped for each constraint:
      	76	bigEndian
      	1	win
      </pre></blockquote>
      
      This can be avoided by changing <tt>n</tt> to an <tt>unsigned int</tt>:
      
      <pre>
      diff --git generic/tclBinary.c generic/tclBinary.c
      index 0f8f77e45..6bbc8fc9f 100644
      --- generic/tclBinary.c
      +++ generic/tclBinary.c
      @@ -2599,7 +2599,8 @@ BinaryEncodeUu(
       {
           Tcl_Obj *resultObj;
           unsigned char *data, *start, *cursor;
      <span style="color:red">-    int offset, count, rawLength, n, i, j, bits, index;</span>
      <span style="color:green">+    int offset, count, rawLength, i, j, bits, index;</span>
      <span style="color:green">+    unsigned int n;</span>
           int lineLength = 61;
           const unsigned char SingleNewline[] = { UCHAR('\n') };
           const unsigned char *wrapchar = SingleNewline;
      </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: "16. Commands A-H"
    14. title initialized to: "avoid signed integer overflow in BinaryEncodeUu()"
    15. type initialized to: "Patch"
  2. Ticket change [7e0d50a591] (rid 196795) by jan.nijtmans on 2021-12-12 18:14:05:

    1. assignee changed to: "jan.nijtmans"
    2. closedate changed to: "2459561.25978733"
    3. closer changed to: "jan.nijtmans"
    4. icomment:
      Fixed now in all branches. Thanks for the report and patch!
      
    5. login: "jan.nijtmans"
    6. mimetype: "text/x-fossil-wiki"
    7. resolution changed to: "Fixed"
    8. status changed to: "Closed"