Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 5427b1eeb1214a20537e1d9b377b586d1d05f57215bb05e9e0d284b200650e67
Ticket: a173f9229fe2fec80dc8d43a16c1d7366fb11945
fcopy and encoding errors: no partial write, no transparency write
User & Date: oehhar on 2023-11-06 09:08:05
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. comment changed 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 changed to: "8.7"
  6. is_private changed to: "0"
  7. login: "oehhar"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "0f366eb3e9e2fcab52b8ebacd197db9047186a5f"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "oehhar"
  14. subsystem changed to: "24. Channel Commands"
  15. title changed to:
    fcopy and encoding errors: no partial write, no transparency write
    
  16. type changed to: "Bug"