Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 2e2d90096d70c035eb6437c503ad038e8e66800d
Ticket: 1462248fffffffffffffffffffffffffffffffff
core dump on Linux while [read]ing file
User & Date: andreas_kupries on 2006-04-04 06:31:54
Changes

  1. icomment:
    Logged In: YES 
    user_id=75003
    
    Ok. I know where the problem is, and I have fix sitting in
    my sandbox. I have no original, so no patches, and
    committing the fix has to wait for SF get their act together
    and CVS back running.
    
    Story time:
    
    (a) ReadChars is called with a buffer containing one byte.
        This buffer has no successor (end-of-input-queue EOIQ).
    (b) The Tcl_ExternalToUtf in ReadChars signals a split
        multi-byte character. Because of EOIQ ReadChars signals
       'nothing read' and 'channel_need_more_data'
    (c) The IO layer does its thing, reading more data.
        This detects EOF, and sets TCL_ENCODING_END.
    (d) ReadChars is called again.
        It now has two buffers. One with split multi-byte at the
        end, a second with the remainder of the multi-byte char.
        It tries to convert the first buffer again.
        This suceeds!! because of the TCL_ENCODING_END.
    
        This is wrong. It should not have suceeded, but failed
        as before. Then causing ReadChars to copy the partial
        multi-byte char to the beginning of the now existing
        next buffer. And then try again, with the modified
        input queue.
    
    In essence the TCL_ENCODING_END is handed to the
    Tcl_ExternalToUtf too early. Yes, there is an EOF pending,
    but right now we have two buffers in the queue, so the first
    one cannot be the end.
    
    There is a contributing bug hidden in the above description:
    Tcl_ExternalToUtf, i.e. Tcl_Utf2UtfProc is accessing memory
    behind the end of its input buffer if the last character is
    the start of a multi-byte character and TEE is set.
    
    And in this case the character found there was a valid
    completion of the multi-byte header, so it consumed 2 bytes
    and reported that, starting the upper layers to psiral out
    of control. Here the memory layout comes into play, causing
    the high sensitivity against any type of change, be it
    different buffer sizes or even a switch to non-interactive
    operation. In most cases the byte read is not a valid
    completion of the multi-byte char, so only one byte is
    consumed (as part of creating canonical utf-8 from the
    non-canonical input) and that keeps the upper layers stable
    and happy. The read information is bad, a multi-byte char
    was broken, but no crash.
    
    This bug has been fixed as well. A quick test with valgrind
    confirmed this bad memory access btw. (using a slightly
    modified make valgrind target).
    
    The whole problem is likely present in 8.5 as well. Fixes
    will done tomorrow. This took the whole day to fully trace
    in its entirety.
    
    
  2. login: "andreas_kupries"
  3. mimetype: "text/plain"
  4. resolution changed to: "Fixed"
  5. username: "andreas_kupries"