Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 48bb1e2e082c6c71d8961ff467c4426486c6c1fcea0669af098611d17b01d113
Ticket: 203792a48c2fbb32f822d8b0a66f7d8fac3e7981
Avoid signed integer overflow in Utf32ToUtfProc()
User & Date: chrstphrchvz on 2023-04-22 08:05:33
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. 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(
    &nbsp;
            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>
    
  5. foundin changed to: "core-8-branch"
  6. is_private changed to: "0"
  7. login: "chrstphrchvz"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "6133eb3026f9b10aa9b7b48da92ae2834fc225b0"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "chrstphrchvz"
  14. subsystem changed to: "44. UTF-8 Strings"
  15. title changed to: "Avoid signed integer overflow in Utf32ToUtfProc()"
  16. type changed to: "Patch"