Artifacts Associated With Ticket ac6792195d
Ticket change [111d158fa3] (rid 196785) by chrstphrchvz on 2021-12-11 06:10:09:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- 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> - 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: "16. Commands A-H"
- title initialized to: "avoid signed integer overflow in BinaryEncodeUu()"
- type initialized to: "Patch"
Ticket change [7e0d50a591] (rid 196795) by jan.nijtmans on 2021-12-12 18:14:05:
- assignee changed to: "jan.nijtmans"
- closedate changed to: "2459561.25978733"
- closer changed to: "jan.nijtmans"
- icomment:
Fixed now in all branches. Thanks for the report and patch!
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"