Overview
| Artifact ID: | 48bb1e2e082c6c71d8961ff467c4426486c6c1fcea0669af098611d17b01d113 |
|---|---|
| Ticket: | 203792a48c2fbb32f822d8b0a66f7d8fac3e7981
Avoid signed integer overflow in Utf32ToUtfProc() |
| User & Date: | chrstphrchvz on 2023-04-22 08:05:33 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/x-fossil-wiki"
- comment changed to:
Encountered during cmdAH.test and encoding.test for Tcl built with <tt>-fsanitize=shift-base</tt>: <blockquote><pre> <b>generic/tclEncoding.c:2779:27: <span style="color:firebrick">runtime error:</span> left shift of 255 by 24 places cannot be represented in type 'int' </b> </pre></blockquote> Avoid by casting to unsigned before shifting: <blockquote><pre> --- generic/tclEncoding.c.orig +++ generic/tclEncoding.c @@ -2774,9 +2774,9 @@ Utf32ToUtfProc( int prev = ch; if (flags & TCL_ENCODING_LE) { <span style="color:firebrick">- ch = (src[3] & 0xFF) << 24 | (src[2] & 0xFF) << 16 | (src[1] & 0xFF) << 8 | (src[0] & 0xFF);</span> <span style="color:green">+ ch = <b>(unsigned int)</b>(src[3] & 0xFF) << 24 | (src[2] & 0xFF) << 16 | (src[1] & 0xFF) << 8 | (src[0] & 0xFF);</span> } else { <span style="color:firebrick">- ch = (src[0] & 0xFF) << 24 | (src[1] & 0xFF) << 16 | (src[2] & 0xFF) << 8 | (src[3] & 0xFF);</span> <span style="color:green">+ ch = <b>(unsigned int)</b>(src[0] & 0xFF) << 24 | (src[1] & 0xFF) << 16 | (src[2] & 0xFF) << 8 | (src[3] & 0xFF);</span> } if (HIGH_SURROGATE(prev) && !LOW_SURROGATE(ch)) { /* Bug [10c2c17c32]. If Hi surrogate not followed by Lo surrogate, finish 3-byte UTF-8 */ </pre></blockquote> - foundin changed to: "core-8-branch"
- is_private changed to: "0"
- login: "chrstphrchvz"
- priority changed to: "5 Medium"
- private_contact changed to: "6133eb3026f9b10aa9b7b48da92ae2834fc225b0"
- resolution changed to: "None"
- severity changed to: "Minor"
- status changed to: "Open"
- submitter changed to: "chrstphrchvz"
- subsystem changed to: "44. UTF-8 Strings"
- title changed to: "Avoid signed integer overflow in Utf32ToUtfProc()"
- type changed to: "Patch"