Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 42ce82ad68094900d9a7b6f45485a39486ee5613
Ticket: 3436609fffffffffffffffffffffffffffffffff
Transforms/Encodings may generate false readable fileevent
User & Date: ferrieux on 2011-11-11 17:29:38
Changes

  1. assignee changed to: "andreas_kupries"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    Channel transforms and (multibyte) encodings break the byte/char 1-to-1 mapping. As a consequence, there are cases where the low-level (resp. raw) channel has a byte ready (as detected by the select() in the notifier, letting a [fileevent readable] fire), but a [read 1] on the hi-level (resp. decoded) channel would block (if blocking) or return the empty string (if not).
    
    The possibility of such "false positives" in readable fileevents is not advertised, and a recurring idiom is
    
       fconfigure $ch -blocking 0
       fileevent $ch readable foo
       proc foo {} {
          set data [read $::ch 1000]
          if {![string length $data]} {close $::ch;clean_things_up}
          # use $data
        }
    
    This idiom, of course, leads to erroneous truncation. The same thing at C level leads to 2762041 and 1945538.
    Note that this mechanism potentially applies to all multibyte encodings and channel transforms. TLS and Zlib are highly suspect of suffering from this, along with the ubiquitous [-encoding utf-8], as shown by the attached script.
    
    Two options:
    
     (1) fix it the hard and clean way, by doing a read-ahead inside the NotifyProc (see 1945538 for details). Do this in the core for non-single-byte encodings, and in the transform-based extensions.
    
     (2) work around it, by strongly documenting the fact. Possibly many scripts to fix. Still some C code to update in extensions making the wrong assumption, to stop them from giving false EOFs.
    
    
    
  4. foundin changed to: "None"
  5. is_private changed to: "0"
  6. priority changed to: "8"
  7. resolution changed to: "None"
  8. status changed to: "Open"
  9. submitter changed to: "ferrieux"
  10. subsystem changed to: "25. Channel System"
  11. title changed to:
    Transforms/Encodings may generate false readable fileevent
    
  12. type changed to: "Bug"