Skip to content
Tcl Source Code History Of Ticket a173f9229fe2fec8
Login

History Of Ticket a173f9229fe2fec8

Artifacts Associated With Ticket a173f9229fe2fec8

  1. Ticket change [5427b1eeb1] (rid 219983) by oehhar on 2023-11-06 09:08:05:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-wiki"
    4. comment initialized to:
      I am currently writing docs for channel encoding errors.
      I don't understand, what happens with fcopy.
      So, allow me, to post this test-report style bug report.
      
      I have made tests with  tip-653 branch (which is very similar to core-8-branch, 7 lines diff) with fcopy and encoding errors.
      
      I imagined 3 cases:
      
         *   Read encoding error with different encodings
         *   Read encoding error with identical encodings and translation
         *   Write encoding errors with different encodings
      
      The test session is as follows:
      
      <h2> Test file creation:</h2>
      In UTF-8, this is at position 0: "A", at position 1: 195, which announces a multi-byte sequence, at position 2 a 65 (ASCII B), which does not continue the multi-byte sequence and thus causes a read encoding error
      
      <verbatim>
      set f [open test_A_195_B.txt wb]; puts -nonewline $f A\xC3B; close $f
      </verbatim>
      
      <H2>Read encoding error with different encodings</H2>
      
      <verbatim>
      % set fr [open test_A_195_B.txt r]
      file12af8f0
      % set fw [open out.txt w]
      file12af430
      % fconfigure $fr -encoding utf-8 -profile strict -translation lf
      % fconfigure $fw -encoding unicode -profile strict -translation lf
      % catch {fcopy $fr $fw} e d
      1
      % set d
      -code 1 -level 0
      -errorstack {INNER {invokeStk1 fcopy file12af8f0 file12af430}}
      -errorcode {POSIX EILSEQ {invalid or incomplete multibyte or wide character}}
      -errorinfo {...} -errorline 1
      % tell $fr
      1
      % flush $fw
      % tell $fw
      0
      % close $fr
      % close $fw
      </verbatim>
      
      So, the file pointer is advanced by 1 on the read side.
      But the correct first byte is not written to the destination file.
      
      IMHO, the destination file should contain "A" and the file pointer should be advanced.
      
      <H2>Read encoding error with same encodings</H2>
      
      Within this test, the only difference to the upper is the fconfigure of the write side:
      
      <verbatim>
      % fconfigure $fw -encoding utf-8 -profile strict -translation lf
      </verbatim>
      
      The result is the same: encoding error thrown, read position advanced.
      
      IMHO, the fcopy page states, that with the same parameters (encoding, translation), data is just copyied and no error detection is done.
      This is not the case. The error is detected.
      
      <h2>Encdoing error on write</h2>
      
      A file is written, which has a unicode character \u2022 not present in iso8859-1.
      Then, this file is read with utf-8 encoding and written with iso-8859-1:
      
      <verbatim>
      % set f [open test_A_2022_B.txt w]; fconfigure $f -encoding utf-8; puts -nonewline $f A\u2022B; close $f
      % set fr [open test_A_2022_B.txt r]
      file12af870
      % set fw [open out.txt w]
      file1277800
      % fconfigure $fr -encoding utf-8 -profile strict -translation lf
      % fconfigure $fw -encoding iso8859-1 -profile strict -translation lf
      % catch {fcopy $fr $fw} e d
      1
      % set d
      -code 1 -level 0
      -errorstack {INNER {invokeStk1 fcopy file12af870 file1277800}}
      -errorcode {POSIX EILSEQ {invalid or incomplete multibyte or wide character}} -errorinfo {...} -errorline 1
      % tell $fr
      5
      % tell $fw
      1
      % close $fr
      % close $fw
      </verbatim>
      
      The one correct by is written. It is interesting, that the read file position is at 5, while it should be at 1.
      
      Thank you all,
      Harald
      
    5. foundin initialized to: "8.7"
    6. is_private initialized to: "0"
    7. login: "oehhar"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "0f366eb3e9e2fcab52b8ebacd197db9047186a5f"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "oehhar"
    14. subsystem initialized to: "24. Channel Commands"
    15. title initialized to:
      fcopy and encoding errors: no partial write, no transparency write
      
    16. type initialized to: "Bug"
  2. Ticket change [37b0f4bc3c] (rid 220205) by oehhar on 2023-11-13 17:47:32:

    1. icomment:
      I think, issue 1 and 3 are bugs. Issue 2 may be a documentation issue.
      
      Starting bug branch [bug-a173f922-fcopy-tell] with a first test with commit [8d4d3146c9].
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"
  3. Ticket change [a8a57b5ccb] (rid 220324) by jan.nijtmans on 2023-11-16 21:57:27:

    1. icomment:
      I agree that 1 is a bug and 2 is a documentation issue.
      
      However, 3 is - indeed - a possibility for data loss. After reading a block of data, the pointer cannot be put back to its original file position (it might come from a socket). So, IMHO, it would be best to use the "-data" key as well for this situation.
      
      This can only happen when all of these are true:
      - the output channel "-profile" is "strict"
      - the input and output encoding are different
      - the output encoding is not UTF-8/UTF-16/UTF-32
      
      So, if any of those 3 conditions is false, we could use the "-data" key here too.
      
      I think this situation is rare: Why would someone want to convert from UTF-8 to another (less capable) encoding? Converting from another encoding to UTF-8 will be much more common.
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  4. Ticket change [a71a2f5c40] (rid 220345) by oehhar on 2023-11-17 08:02:51:

    1. icomment:
      Hi Jan,
      
      thank you for the good thoughts.
      
      Even if there is data loss possible on the 3rd case, I would just accept that data loss.
      
      The fcopy logically as:
      
      <verbatim>
      if {[catch {read $rf} data]} {
          # read error handling
      } elseif {[catch {puts -nonewline $wf $data} err]} {
          # write data error
      }  
      </verbatim>
      
      Currently, if we loose data on the puts, it is lost - point.
      
      So, I would go to document for fcopy on encoding errors:
      
         *   On read encoding errors, the data before the error is written. The current read file pointer is on the error position. A recovery is possible by fixing the issue and continue like:
      
      <verbatim>
      fconfigure $rf -encoding binary
      fcopy $rf $wf
      </verbatim>
      
         *   On write encoding errors, the data before the write error is written. The data causing the error and eventual following data is lost.
      
      Is there a way, that a script may make the difference between read and write encoding error?
      Both will throw "EILSEQ" error and have the same error message.
      
      Thank you and take care,
      Harald
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"
  5. Ticket change [a310a4733a] (rid 220401) by oehhar on 2023-11-18 18:15:24:

    1. icomment:
      For the same encoding case, the code to detect "verbatim copy" is as follows (tclIO.c Line 9496):
      
      <verbatim>
         moveBytes = inStatePtr->inEofChar == '\0'	/* No eofChar to stop input */
      	    && inStatePtr->inputTranslation == TCL_TRANSLATE_LF
      	    && outStatePtr->outputTranslation == TCL_TRANSLATE_LF
      	    && inStatePtr->encoding == outStatePtr->encoding
      	    && ENCODING_PROFILE_GET(inStatePtr->inputEncodingFlags) == TCL_ENCODING_PROFILE_TCL8
      	    && ENCODING_PROFILE_GET(outStatePtr->outputEncodingFlags) == TCL_ENCODING_PROFILE_TCL8;
      </verbatim>
      
      So, the conditions are:
      
         *   No EOF char
         *   Translation: LF
         *   input encoding equal output encoding
         *   profile: TCL8
      
      I am not sure, if this should not be profile agnostic.
      Specially, profile TCL8 may disappear and I don't like to set it anywhere.
      
      But anyway, that is the current code.
      
      Lets document it like that and point.
      
      Take care,
      Harald
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"
  6. Ticket change [21b3f2929a] (rid 220422) by oehhar on 2023-11-20 13:26:19:

    1. icomment:
      First bug fixed by commit [b9f611b9a0].
      The remaining issues are documentation issues.
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"
  7. Ticket change [8745243d8b] (rid 220435) by oehhar on 2023-11-20 14:47:42:

    1. icomment:
      I have thought about the case with same encodings.
      
      The verbatim copy should only happen, if both encodings are binary.
      
      For legacy reasons, it happens for any encoding in tcl8 profile.
      This may be removed in future versions.
      
      I think, I will document it like that.
      
      Thank you and take care,
      Harald
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"
  8. Ticket change [52d15991f9] (rid 220446) by oehhar on 2023-11-20 17:03:51:

    1. icomment:
      Documentation added to core-8-branch and main.
      Closing the ticket.
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"
  9. Ticket change [8d685beec8] (rid 220447) by oehhar on 2023-11-20 17:04:02:

    1. closedate changed to: "2460269.21114172"
    2. closer changed to: "oehhar"
    3. login: "oehhar"
    4. mimetype: "text/plain"
    5. resolution changed to: "Fixed"
    6. status changed to: "Closed"