Skip to content
Tcl Source Code History Of Ticket b3977d199b
Login

History Of Ticket b3977d199b

Artifacts Associated With Ticket b3977d199b

  1. Ticket change [e904ce3764] (rid 202281) by apnadkarni on 2022-07-03 06:22:57:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-markdown"
    4. comment initialized to:
      When a CR-LF in an incoming stream is split across packets, and the LF-containing packet is not received when the CR-containing packet is read by the channel, the application receives an spurious empty line on `gets` invocations. To illustrate, run the attached server.tcl and client.tcl files. Seen output is 
      
      ```
      d:\src\tcltk\console\tests>tclsh client.tcl
      <abc>
      <defghi>
      <>
      <jkl>
      ```
      
      Note the extra <> line which should not be present.
      
      Note that this is not specific to socket streams although that's where it is easiest to demonstrate. Also happens on Linux (at least) so not Windows specific.
      
      Marking as severe because although the conditions to trigger are extremely rare, any data corruption in transit is a Bad Thing.
      
    5. foundin initialized to: "8.6"
    6. is_private initialized to: "0"
    7. login: "apnadkarni"
    8. priority initialized to: "5 Medium"
    9. resolution initialized to: "None"
    10. severity initialized to: "Severe"
    11. status initialized to: "Open"
    12. submitter initialized to: "apnadkarni"
    13. subsystem initialized to: "25. Channel System"
    14. title initialized to:
      Channel gets inserts spurious empty lines on receiving torn CR-LF
      
    15. type initialized to: "Bug"
  2. Add attachment "server-torncrlf.tcl" [841247ab55] (rid 202283) by apnadkarni on 2022-07-03 06:27:15.

  3. Add attachment "client-torncrlf.tcl" [48f4a5eb71] (rid 202285) by apnadkarni on 2022-07-03 06:27:49.

  4. Ticket change [8f2709c246] (rid 202286) by apnadkarni on 2022-07-03 06:42:53:

    1. icomment:
      Here is my analysis of what is happening (most action is inside Tcl_GetObj)
      
      When a CR is read from the channel buffer but the accompanying LF has not arrived, the channel code passes up the line as the `gets` result and also remembers that a CR has been seen by [setting a flag](https://core.tcl-lang.org/tcl/file?ci=651b1008fbc7f7ed&name=generic/tclIO.c&ln=4794)
      
      When subsequently the LF is received, the channel subsystem correctly 
      [skips](https://core.tcl-lang.org/tcl/file?ci=651b1008fbc7f7ed&name=generic/tclIO.c&ln=4753-4773) it by [bumping the pointer](https://core.tcl-lang.org/tcl/file?ci=651b1008fbc7f7ed&name=generic/tclIO.c&ln=4766) into the receive buffer past the LF.
      
      However, later in the code, the pointer offset is [reset to its old value](https://core.tcl-lang.org/tcl/file?ci=651b1008fbc7f7ed&name=generic/tclIO.c&ln=4900) which means the next gets sees it as a new line and in auto translation mode returns an empty line as a result.
      
      This last reset of value is the root of the problem. I do not understand all the manipulations of the buffers and offsets and why that is necessary so hesitant to suggest a fix.
      
    2. login: "apnadkarni"
    3. mimetype: "text/x-markdown"
  5. Ticket change [f9d9b909e9] (rid 202287) by apnadkarni on 2022-07-03 06:46:30:

    1. comment changed to:
      When a CR-LF in an incoming stream is split across packets, and the LF-containing packet is not received when the CR-containing packet is read by the channel, the application receives an spurious empty line on `gets` invocations. To illustrate, run the attached server.tcl and client.tcl files. Seen output is 
      
      ```
      d:\src\tcltk\console\tests>tclsh client.tcl
      <abc>
      <defghi>
      <>
      <jkl>
      ```
      
      Note the extra <> line which should not be present.
      
      Note that this is not specific to socket streams although that's where it is easiest to demonstrate. Also happens on Linux (at least) so not Windows specific. The channel needs to be non-blocking and in auto translation mode.
      
      Marking as severe because although the conditions to trigger are extremely rare, any data corruption in transit is a Bad Thing.
      
    2. login: "apnadkarni"
    3. mimetype: "text/plain"
  6. Ticket change [e70d8deb1e] (rid 202328) by oehhar on 2022-07-04 14:32:53:

    1. icomment:
      Ashok,
      
      great finding.
      
      When I was in the Windows socket driver update, Donald Porter was the most experienced person in this field. I recommend sending an E-Mail to Donald or asking on the core list.
      
      I found this part of TCL surprisingly difficult.
      
      Take care,
      Harald
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"
  7. Ticket change [92d0682a3e] (rid 202790) by dgp on 2022-07-21 15:11:36:

    1. assignee changed to: "dgp"
    2. login: "dgp"
    3. mimetype: "text/plain"
  8. Ticket change [6019c3828c] (rid 202801) by sebres on 2022-07-21 16:47:31:

    1. icomment:
      Test illustrating potentially undefined behavior (delay dependent):
      
      ```
      proc accept {so args} {
        fconfigure $so -translation binary
        puts -nonewline $so "1 line\r"
        puts -nonewline $so "\n2 li"
        flush $so
        #Now force separate packets
        puts -nonewline $so "ne\r"
        flush $so
        if {[incr ::cnt] & 1} {
          after 20 {set ::cnt $::cnt}; vwait ::cnt; # simulate short delay (and client can process events)
        } else {
          after 20; # small delay without processing events (just to avoid large output), client would receive the buffer in single chunk
        }
        puts -nonewline $so "\n3 line"
        flush $so
        close $so
      }
      set so [socket -server accept 10000]
      proc test {} {
        if {1} {
          set chan [socket 127.0.0.1 10000]
        } else {
          set chan stdin
        }
        fileevent $chan readable [list apply {chan {
          if {[gets $chan line] >= 0} {
            puts <$line>
          } elseif {[eof $chan]} {
            close $chan
            set ::done 1
          }
        }} $chan]
        fconfigure $chan -blocking 0 -buffering line
        vwait ::done
        puts "----$::cnt---"
        update
      }
      timerate {test} 100
      ```
      The result will show an extra NL by each odd attempt (due to immediate processing of every buffer) and no extra NL by each even attempt (buffers coming as 1 piece):
      ```
      <1 line>
      <2 line>
      <>
      <3 line>
      ----1---
      <1 line>
      <2 line>
      <3 line>
      ----2---
      <1 line>
      <2 line>
      <>
      <3 line>
      ----3---
      <1 line>
      <2 line>
      <3 line>
      ----4---
      <1 line>
      <2 line>
      <>
      <3 line>
      ----5---
      ```
      
    2. login: "sebres"
    3. mimetype: "text/x-markdown"
  9. Ticket change [f51006574e] (rid 202805) by sebres on 2022-07-21 19:26:50:

    1. icomment:
      [350f5b9a9e694bca] implements the test-cases covering the -translation auto bug, just ...
      
      Just now I guess I found another inconsistency related to auto translation by pure "\r" EOL-char: I wanted to add regression test (which tcl seems to miss right now) to cover simple QA communication with auto-translation for CR-only case and the test failed after all - it must generate the same result by "cr" and "auto" translation, but it seems to truncate 1 char received by [gets] in second QA round in "auto" translation case:
      <code><pre>
          ---- Result was:
          <b style="color:red">{cr lf} {really client?} yes auto {unexpected input "really client"} wrong</b>
          ---- Result should have been (exact matching):
          <b style="color:green">{cr lf} {really client?} yes auto {really client?} yes</b>
          <b>==== io-29.36.1 FAILED</b>
      </pre></code>
      This is really weird, because I could swear I saw that working, just tested it with older 8.5 and the result is the same
      
    2. login: "sebres"
    3. mimetype: "text/x-fossil-wiki"
  10. Ticket change [d40981043d] (rid 202827) by sebres on 2022-07-22 16:33:06:

    1. icomment:
      As for failed test io-29.36.1, it was my mistake:
      translation {auto} on client-side caused that answer <code>"client"</code> reached the server-side as <code>"client\r\n"</code>, and <code>[gets]</code> by translation {binary} behaves nearly identical to {lf} mode, so server sends <code>"really client\r?\r"</code> in the next round, therefore looks like "?"-char got trimmed out (but in fact the client sent inappropriate answer).
      
      [5f7f4ab975] fixes that - switching to {auto lf} now, similar to first attempt with {cr lf}, so io-29.36.1 works fine and will cover the possible regression if this bug becomes fixed incompatibly.
      
    2. login: "sebres"
    3. mimetype: "text/x-fossil-wiki"
  11. Ticket change [d49c705a51] (rid 202833) by sebres on 2022-07-22 17:43:28:

    1. icomment: "[d2a8078086] must fix it ultimately"
    2. login: "sebres"
    3. mimetype: "text/x-fossil-wiki"
    4. resolution changed to: "Fixed"
    5. status changed to: "Pending"
  12. Ticket change [cde8e24f54] (rid 202890) by jan.nijtmans on 2022-07-25 21:29:10:

    1. assignee changed to: "sebres"
    2. icomment:
      @apnadkarni, is this bug fixed in your opinion? If so, let's go for it!
      
    3. login: "jan.nijtmans"
    4. mimetype: "text/x-fossil-wiki"
  13. Ticket change [d1f262a5a5] (rid 202899) by sebres on 2022-07-27 13:31:59:

    1. assignee changed to: "dgp"
    2. closedate changed to: "2459788.06388384"
    3. closer changed to: "sebres"
    4. icomment: "fixed in [a3ed092aab], thus close"
    5. login: "sebres"
    6. mimetype: "text/x-fossil-wiki"
    7. status changed to: "Closed"