Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 8acabbadb8957321f31f9c3263487add22ffd0693ae3abf2ec8ed3e4b76708f3
Ticket: bd94500678e837d7ed50cf6d5000df8f38cd5e39
SEGFAULT by conversion of unicode (out of BMP) to byte-array.
User & Date: sebres on 2019-02-06 10:08:37
Changes

  1. icomment:
    <i>> why would extensions modify 'ch' in-between?</i>
    
    Well, I found already 2 pieces within cycles on my side, that doing this: the one by compare of 2 uni-strings (both have set ch to zero exactly as in fixed case), and another by fast compression of string (ch = uni-char from a dictionary, if it is within and shorter in bits).
    
    The point is - in constructs like following, you could never be sure that "ch" has been never changed:
    <code><pre>
        while ( src < srcEnd ) {
    	// ...here... (like `Tcl_UniChar ch = 0; /* to silence stupid compiler warning */`)
    	src += TclUtfToUniChar(src, &ch);
    	// ...or even here... (like `ch = SomeTransform(ch); *dst1++ = ch; *dst2++ = ch;`)
    	// ...or even calc... (like `ch = OperationAsPartOfCheckSum(ch); ...; sum += ch;`)
        }
    </pre></code>
    Just because previously the return value was always >= 1 (and also documented this way "The return value is the number of bytes read from src."). 
    And it is very very long time so.
    
    And simply think about what this could cause then (endless cycles, buffer overrun, etc).<br/>
    Would not we pay too high penalty to retain stubs/EIAS/compatibility for rare case "char is out of BMP" (and glyphs are mostly unneeded by 99% of app's).
    
    <i>> I'm open for suggesions for improvement</i>
    
    And I have some of these:
    <ul>
    <li>either a new function like <code>Tcl_UtfToUniCharEx/TclUtfToUniCharEx</code> that doing the new implementation (and let both previous <code>Tcl_UtfToUniChar/TclUtfToUniChar</code> untouched).
    Still better this new function could get new param <code>len</code>, that I always missed (one should previously be sure that <code>src</code> is NTS or long enough to avoid access violation).
    </li>
    <li>or an intended change of Stubs, so some new parameter like <code>Tcl_UtfToUniChar(srcPtr, ch, bmpOnly)</code> that controls new implementation as well as forses the developer change (and verify) his code.</li>
    </ul>
    
    Both ways retain the stability (avoids vulni/SF/BO) and give developers a chance for correct processing out of BMP chars (if it is needed at all) using this new function (stub).
    
    Anyway are you agree that a theoretical incompatibility is many many times better as BO/segfault (or even potential vulnerability)?
    
  2. login: "sebres"
  3. mimetype: "text/x-fossil-wiki"