Skip to content
Tcl Source Code History Of Ticket 879a0747bee593e2
Login

History Of Ticket 879a0747bee593e2

Artifacts Associated With Ticket 879a0747bee593e2

  1. Ticket change [ae939da698] (rid 141568) by erikleunissen on 2015-04-19 15:11:20:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized to:
      Tcl segfaults when reading the attached file "workfile".
      The supplied script "exercise.tcl" makes that happen for you.
      
      The segfaults occurs with Tcl releases 8.5.18 and 8.6.4, and not with 8.4.20.
      Platform info and full back trace have been appended.
      
      Aside: the file "workfile" is no clever concoction. It's a real-world file (with another name) that exists in a user-specific configuration directory for my KDE-desktop. Tcl stumbled across it, when traversing the filesystem in search for specific patterns. The file contains some invalid UTF-8 characters. If you know up front that this file is coming, then you probably want to open it in binary mode and all is well. Of course, Tcl ought not segfault when reading it in text mode.
      
      Sincerely,
      
      Erik Leunissen
      --
      Platform and encoding settings:
      % parray tcl_platform
      tcl_platform(byteOrder)   = littleEndian
      tcl_platform(machine)     = x86_64
      tcl_platform(os)          = Linux
      tcl_platform(osVersion)   = 3.11.6-4-desktop
      tcl_platform(platform)    = unix
      tcl_platform(pointerSize) = 8
      tcl_platform(user)        = erik
      tcl_platform(wordSize)    = 8
      % encoding system
      utf-8
      --
      
      Full back trace with Tcl 8.5.18:
      
      #0  0x00007f59f3e184c9 in raise () from /lib64/libc.so.6
      No symbol table info available.
      #1  0x00007f59f3e19958 in abort () from /lib64/libc.so.6
      No symbol table info available.
      #2  0x00007f59f3e11296 in __assert_fail_base () from /lib64/libc.so.6
      No symbol table info available.
      #3  0x00007f59f3e11342 in __assert_fail () from /lib64/libc.so.6
      No symbol table info available.
      #4  0x00007f59f475b72b in DoReadChars (chanPtr=0xacf290, objPtr=0xacea30, toRead=-11037, appendFlag=0)
          at /usr/local/src/SOURCES/tcl8.5.18/unix/../generic/tclIO.c:5393
              statePtr = 0xacbcf0
              bufPtr = 0xad10f0
              copied = 11036
              copiedNow = -1
              result = 0
              encoding = 0xaa6f30
              binaryMode = 0
              factor = 1027
              __PRETTY_FUNCTION__ = "DoReadChars"
      #5  0x00007f59f475b36b in Tcl_ReadChars (chan=0xacf290, objPtr=0xacea30, toRead=-1, appendFlag=0)
          at /usr/local/src/SOURCES/tcl8.5.18/unix/../generic/tclIO.c:5219
              chanPtr = 0xacf290
              statePtr = 0xacbcf0
      #6  0x00007f59f4762fcd in Tcl_ReadObjCmd (dummy=0x0, interp=0xaa89a0, objc=2, objv=0xaaaee0)
          at /usr/local/src/SOURCES/tcl8.5.18/unix/../generic/tclIOCmd.c:462
              chan = 0xacf290
              newline = 0
              i = 2
              toRead = -1
              charactersRead = 0
              mode = 2
              resultPtr = 0xacea30
              chanObjPtr = 0xac8120
      #7  0x00007f59f46d1995 in TclEvalObjvInternal (interp=0xaa89a0, objc=2, objv=0xaaaee0, command=0xacf1dd "read $fd]\n", 
          length=8, flags=0) at /usr/local/src/SOURCES/tcl8.5.18/unix/../generic/tclBasic.c:3727
              cmdPtr = 0xab1630
              iPtr = 0xaa89a0
              newObjv = 0xac81e0
              i = 0
              savedVarFramePtr = 0x0
              varFramePtr = 0xaaa770
              code = 0
              traceCode = 0
              checkTraces = 1
              traced = 0
              savedNsPtr = 0x0
              lookupNsPtr = 0x0
              commandPtr = 0x0
      #8  0x00007f59f46d2e5d in TclEvalEx (interp=0xaa89a0, script=0xacf1dd "read $fd]\n", numBytes=8, flags=0, line=4, 
          clNextOuter=0x0, outerScript=0xacf1a0 "#! /usr/local/bin/tclsh\n\nset fd [open ./workfile r]\nset txt [read $fd]\n")
          at /usr/local/src/SOURCES/tcl8.5.18/unix/../generic/tclBasic.c:4426
              wordLine = 4
              wordCLNext = 0x0
              objectsNeeded = 2
              wordStart = 0xacf1e2 "$fd]\n"
              numWords = 2
              iPtr = 0xaa89a0
              p = 0xacf1dd "read $fd]\n"
              next = 0xaaac30 "Ы\252"
              minObjs = 20
              objv = 0xaaaee0
              objvSpace = 0xaaaee0
              expand = 0xaaaf90
              lines = 0xaaaff0
              lineSpace = 0xaaaff0
              tokenPtr = 0xaaad18
              commandLength = 0
              bytesLeft = 8
              expandRequested = 0
              code = 0
              savedVarFramePtr = 0xaaa770
              allowExceptions = 0
              gotParse = 1
              i = 202723952
              objectsUsed = 2
              parsePtr = 0xaaac40
              eeFramePtr = 0xaaae90
              stackObjArray = 0xaaaee0
              expandStack = 0xaaaf90
              linesStack = 0xaaaff0
              clNext = 0x0
      #9  0x00007f59f478702d in TclSubstTokens (interp=0xaa89a0, tokenPtr=0xaaa908, count=1, tokensLeftPtr=0x0, line=4, 
          clNextOuter=0x0, outerScript=0xacf1a0 "#! /usr/local/bin/tclsh\n\nset fd [open ./workfile r]\nset txt [read $fd]\n")
          at /usr/local/src/SOURCES/tcl8.5.18/unix/../generic/tclParse.c:2320
              theline = 4
              iPtr = 0xaa89a0
              appendObj = 0x0
              append = 0x0
              appendByteLength = 0
              utfCharBytes = "\320", <incomplete sequence \351\254>
              result = 0x0
              code = 0
              isLiteral = 0
              maxNumCL = 0
              numCL = 0
              i = 0
              adjust = 0
              clPosition = 0x0
              iPtr = 0xaa89a0
              inFile = 2
      #10 0x00007f59f46d2886 in TclEvalEx (interp=0xaa89a0, 
          script=0xacf1a0 "#! /usr/local/bin/tclsh\n\nset fd [open ./workfile r]\nset txt [read $fd]\n", numBytes=71, flags=0, 
          line=4, clNextOuter=0x0, 
          outerScript=0xacf1a0 "#! /usr/local/bin/tclsh\n\nset fd [open ./workfile r]\nset txt [read $fd]\n")
          at /usr/local/src/SOURCES/tcl8.5.18/unix/../generic/tclBasic.c:4314
              wordLine = 4
              wordCLNext = 0x0
              objectsNeeded = 2
              wordStart = 0xacf1dc "[read $fd]\n"
              numWords = 3
              iPtr = 0xaa89a0
              p = 0xacf1d4 "set txt [read $fd]\n"
              next = 0xacf1d4 "set txt [read $fd]\n"
              minObjs = 20
              objv = 0xaaaad0
              objvSpace = 0xaaaad0
              expand = 0xaaab80
              lines = 0xaaabe0
              lineSpace = 0xaaabe0
              tokenPtr = 0xaaa8f0
              commandLength = 0
              bytesLeft = 19
              expandRequested = 0
              code = 0
              savedVarFramePtr = 0xaaa770
              allowExceptions = 0
              gotParse = 1
              i = 3
              objectsUsed = 2
              parsePtr = 0xaaa830
              eeFramePtr = 0xaaaa80
              stackObjArray = 0xaaaad0
              expandStack = 0xaaab80
              linesStack = 0xaaabe0
              clNext = 0x0
      #11 0x00007f59f46d21e7 in Tcl_EvalEx (interp=0xaa89a0, 
          script=0xacf1a0 "#! /usr/local/bin/tclsh\n\nset fd [open ./workfile r]\nset txt [read $fd]\n", numBytes=71, flags=0)
          at /usr/local/src/SOURCES/tcl8.5.18/unix/../generic/tclBasic.c:4083
      No locals.
      #12 0x00007f59f476b07d in Tcl_FSEvalFileEx (interp=0xaa89a0, pathPtr=0xac83f0, encodingName=0x0)
          at /usr/local/src/SOURCES/tcl8.5.18/unix/../generic/tclIOUtil.c:1859
              length = 71
              result = 1
              statBuf = {st_dev = 2055, st_ino = 226703, st_nlink = 1, st_mode = 33261, st_uid = 1000, st_gid = 100, 
                __pad0 = 0, st_rdev = 0, st_size = 71, st_blksize = 4096, st_blocks = 8, st_atim = {tv_sec = 1429451988, 
                  tv_nsec = 733091879}, st_mtim = {tv_sec = 1429451980, tv_nsec = 908031747}, st_ctim = {tv_sec = 1429451980, 
                  tv_nsec = 924031870}, __unused = {0, 0, 0}}
              oldScriptFile = 0x0
              iPtr = 0xaa89a0
              string = 0xacf1a0 "#! /usr/local/bin/tclsh\n\nset fd [open ./workfile r]\nset txt [read $fd]\n"
              chan = 0xacf290
              objPtr = 0xace940
      #13 0x00007f59f477415d in Tcl_Main (argc=-1, argv=0x7fff0c155a48, appInitProc=0x4009ae <Tcl_AppInit>)
          at /usr/local/src/SOURCES/tcl8.5.18/unix/../generic/tclMain.c:440
              path = 0xac83f0
              resultPtr = 0x7fff0c155a30
              argvPtr = 0xac8330
              commandPtr = 0x0
              encodingName = 0x0
              prompt = PROMPT_START
              code = 0
              length = 12
              tty = 1
              exitCode = 0
              inChannel = 0x4009ae <Tcl_AppInit>
              outChannel = 0x7f59f4a11c67 <_dl_fixup+247>
              errChannel = 0x7fff0c155950
              interp = 0xaa89a0
              appName = {string = 0x7fff0c155780 "", length = 0, spaceAvl = 200, 
                staticSpace = "\000xercise.tcl\000\000\000\000\001\000\000\000Y\177\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000HQ\302\364Y\177\000\000(m\336\363Y\177\000\000\250\061\337\363Y\177\000\000\360X\025\f\377\177\000\000\070\365\330\003", '\000' <repeats 12 times>, "\240T\302\364Y\177\000\000\020X\025\f\377\177\000\000\000X\025\f\377\177\000\000\f\302\342\310\000\000\000\000\067\006@\000\000\000\000\000\377\377\377\377\000\000\000\000\360\003@\000\000\000\000\000@\365i\364Y\177\000\000H'\302\364Y\177\000\000PY\025\f\377\177\000\000\300\217\277\364Y\177\000\000\200Y\025\f\377\177\000\000\240T\302\364Y\177\000\000\250Y\025\f\377\177\000"}
      #14 0x00000000004009a7 in main (argc=2, argv=0x7fff0c155a38)
          at /usr/local/src/SOURCES/tcl8.5.18/unix/../unix/tclAppInit.c:85
      No locals.
      -- end of message --
      
    5. foundin initialized to: "8.5.18"
    6. is_private initialized to: "0"
    7. login: "erikleunissen"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "609f4c7ecf7dbb7a46acdc7eb164753d196088a6"
    10. resolution initialized to: "None"
    11. severity initialized to: "Severe"
    12. status initialized to: "Open"
    13. submitter initialized to: "erikleunissen"
    14. subsystem initialized to: "24. Channel Commands"
    15. title initialized to: "Segfault when reading a specific file"
    16. type initialized to: "Bug"
  2. Add attachment "workfile" [4a642f2475] (rid 141569) by erikleunissen on 2015-04-19 15:12:26.

  3. Add attachment "exercise.tcl" [6f154dadf1] (rid 141570) by erikleunissen on 2015-04-19 15:12:56.

  4. Ticket change [9993db5fee] (rid 141571) by ferrieux on 2015-04-19 21:07:43:

    1. icomment:
      Cannot repro, be it on 8.5.18, 8.6.4, or trunk; both debug and nondebug builds.
      System is an AMD64 Debian wheezy:
      
       % info patch
       8.5.18
       % parray tcl_platform
       tcl_platform(byteOrder)   = littleEndian
       tcl_platform(machine)     = x86_64
       tcl_platform(os)          = Linux
       tcl_platform(osVersion)   = 3.2.0-4-amd64
       tcl_platform(platform)    = unix
       tcl_platform(pointerSize) = 8
       tcl_platform(user)        = alex
       tcl_platform(wordSize)    = 8
      
      Maybe something with the filesystem your workfile is stored on ? Mine is:
      
       /dev/disk/by-uuid/da66d2f0-ebbb-4c83-b374-dfe13a90fe5e on / type ext4 (rw,relatime,errors=remount-ro,user_xattr,barrier=1,data=ordered)
      
      Maybe a low-level I/O error at a specific spot ?
      Please give details on fs and attach an strace of the execution.
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
  5. Add attachment "strace.out" [d772209343] (rid 141572) by erikleunissen on 2015-04-20 09:44:32.

  6. Ticket change [887f7302ed] (rid 141573) by erikleunissen on 2015-04-20 09:46:54:

    1. icomment:
      Hmm, weird.
      
      Filesystem: /dev/sda7 /home ext3 rw,relatime,data=ordered 0 0
      
      Strace output attached.
      
      Erik
      --
      
    2. login: "erikleunissen"
    3. mimetype: "text/plain"
  7. Ticket change [d0fc327551] (rid 141574) by erikleunissen on 2015-04-20 09:56:05:

    1. icomment:
      B.t.w.
      
      With a copy of workfile at another location (on the same file system), but also with a copy on another file system[*], the issue remains the same.
      
      [*] /dev/sda15 /mnt/local/heavy-duty ext4 rw,relatime,data=ordered 0 0
      
    2. login: "erikleunissen"
    3. mimetype: "text/plain"
  8. Ticket change [55d533534c] (rid 141579) by ferrieux on 2015-04-20 12:52:13:

    1. assignee changed to: "dgp"
    2. icomment:
      Nothing obviously suspect in the strace :/
      I get the same 2 full reads + 1 short + 1 empty as you do:
      
       read(4, "JL\32\0\0\0+13717 at http://dot.kde.o"..., 4096) = 4096
       read(4, "rg/Lokalize\" rel=\"nofollow\">Loka"..., 4096) = 4096
       read(4, "class=\"taxonomy-image-links\"><im"..., 4096) = 2865
       read(4, "", 1231)                       = 0
      
      Two things:
      
       - please post environment (output from "env"), in case something hides in one of the locale-oriented variables . I have an [encoding system] also equal to "utf-8", but the devil may hide in the details.
      
       - the failing assertion is:
      
      	assert(!GotFlag(statePtr, CHANNEL_EOF)
      		|| GotFlag(statePtr, CHANNEL_STICKY_EOF)
      		|| Tcl_InputBuffered((Tcl_Channel)chanPtr) == 0);
      
      Added in this commit:
      
       2014-11-06 16:34 [16bdf667aa] Stop Tcl forcing EOF condition on channels to be   
       permanent. It may be fleeting, and all parts of Tcl channel ecosystem have to 
       deal with that. New assertions and tests to keep us on track.(user: dgp, tags: 
       trunk)
      
      Since it is not immediately clear to me, I'll assign to Don for comment on all three parts (a comment in the code itself would be welcome too).
      
      (I assume that since we've read the whole file, the one which should evaluate to true is CHANNEL_STICKY_EOF, which is a recent addition best mastered by Don)
      
      I am still *very* interested to see how this can heisenbug depending on libc version, or environment, or whatever...
      
    3. login: "ferrieux"
    4. mimetype: "text/plain"
  9. Add attachment "env.txt" [a64d680221] (rid 141580) by erikleunissen on 2015-04-20 13:56:57.

  10. Ticket change [907ed0031a] (rid 141581) by erikleunissen on 2015-04-20 14:04:40:

    1. icomment:
      Several remarks:
      
      - Output of env attached.
      
      - The failing assertion is triggered only when built without -DNDEBUG, which is the default for debug builds, but which lacks by default for optimized builds.
      
      - To start delimiting the extent of this issue, I ran ./exercise on a completely different machine:
      % parray tcl_platform
      tcl_platform(byteOrder)   = littleEndian
      tcl_platform(machine)     = armv7l
      tcl_platform(os)          = Linux
      tcl_platform(osVersion)   = 3.14.33-ti-r50
      tcl_platform(platform)    = unix
      tcl_platform(pointerSize) = 4
      tcl_platform(user)        = root
      tcl_platform(wordSize)    = 4
      % set tcl_patchLevel
      8.5.18
      
      The segfault occurred likewise.
      --
      
    2. login: "erikleunissen"
    3. mimetype: "text/plain"
  11. Ticket change [db551b7eee] (rid 141582) by erikleunissen on 2015-04-20 14:11:52:

    1. icomment:
      Uhmm, that was confusing. I meant:
      
      - The failing assertion is triggered only when Tcl was built without -DNDEBUG, which is the default for debug builds. Optimized builds, however, do define NDEBUG by default, which disables assertions.
      
    2. login: "erikleunissen"
    3. mimetype: "text/plain"
  12. Ticket change [8ca08a475c] (rid 141584) by ferrieux on 2015-04-20 16:57:59:

    1. icomment:
      Oh, sorry, indeed my "debug" builds were only via selection of the appropriate CFLAGS=$(CFLAGS_DEBUG). I never noticed that this does *not* properly set NDEBUG !
      
      Also, I was under the impression that assertions in Tcl were rather sanity checks that we'd rather not disable, implemented as vanilla "if...Tcl_Panic". True NDEBUG-controlled assertions had escaped my attention :P
      
      So now, yes, I do reproduce. Nothing to do with OS or environment.
      Now all that's left to decipher is why this specific file has trouble setting the "sticky eof" state.
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
  13. Ticket change [42d6fa4e16] (rid 141587) by ferrieux on 2015-04-20 18:12:07:

    1. icomment:
      OK, the specificity of the file is very simple: it ends in mid-utf8-char ;)
      So you can reproduce with a mush smaller file:
      
       set ff [open foo w]
       fconfigure $ff -translation  binary
       puts -nonewline $ff "hello\xD7"
       close $ff
       set ff [open foo r] ;# here we inherit [encoding system]==utf-8
       set x [read $ff]
      
      So I guess that the multibyte machinery somehow gets into the way of the varied EOF flags. That should (and will) be cured, though the circumstances of the discovery are a bit contorted (you're basically reading a binary file with an utf-8 channel encoding).
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
  14. Add attachment "bt.txt" [f77968a804] (rid 141589) by ferrieux on 2015-04-20 20:08:03.

  15. Ticket change [02a11b7521] (rid 141590) by ferrieux on 2015-04-20 20:08:44:

    1. comment changed to:
      Tcl segfaults when reading the attached file "workfile".
      The supplied script "exercise.tcl" makes that happen for you.
      
      The segfaults occurs with Tcl releases 8.5.18 and 8.6.4, and not with 8.4.20.
      Platform info and full back trace have been appended.
      
      Aside: the file "workfile" is no clever concoction. It's a real-world file (with another name) that exists in a user-specific configuration directory for my KDE-desktop. Tcl stumbled across it, when traversing the filesystem in search for specific patterns. The file contains some invalid UTF-8 characters. If you know up front that this file is coming, then you probably want to open it in binary mode and all is well. Of course, Tcl ought not segfault when reading it in text mode.
      
      Sincerely,
      
      Erik Leunissen
      --
      Platform and encoding settings:
      % parray tcl_platform
      tcl_platform(byteOrder)   = littleEndian
      tcl_platform(machine)     = x86_64
      tcl_platform(os)          = Linux
      tcl_platform(osVersion)   = 3.11.6-4-desktop
      tcl_platform(platform)    = unix
      tcl_platform(pointerSize) = 8
      tcl_platform(user)        = erik
      tcl_platform(wordSize)    = 8
      % encoding system
      utf-8
      --
      
      Full back trace with Tcl 8.5.18: see attached bt.txt
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
  16. Ticket change [585842177c] (rid 141592) by dgp on 2015-04-21 02:14:08:

    1. icomment:
      
      Thanks for the good demo.
      
      The dgp-read-bytes branch introduced new handling
      of this case about a year back.
      
      At a first glance, it appears to me Tcl was getting
      this case wrong before that, and gets it wrong in
      a different way now.
      
      But more careful examination is in order to firm up
      those initial impressions.  Thanks for the report.
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. priority changed to: "8"
    5. title changed to: "Incomplete multibyte char @eof -> failed read"
  17. Ticket change [b00697174d] (rid 141596) by dgp on 2015-04-21 17:34:34:

    1. icomment:
      
      This is a descendant of Bug 1462248.
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  18. Ticket change [4b58a5b933] (rid 141597) by dgp on 2015-04-21 18:24:46:

    1. icomment:
      
      The likely fix is now on branch bug-879a0747be.
      
      Holding back from merges until I get some proper
      tests in place.
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  19. Ticket change [1dc2f48640] (rid 141622) by dgp on 2015-04-24 20:17:29:

    1. closedate changed to: "2457137.34548134"
    2. closer changed to: "dgp"
    3. icomment:
      
      More complete fix with tests committed to 8.5 and trunk branches.
      
    4. login: "dgp"
    5. mimetype: "text/plain"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
  20. Ticket change [edbb8d5493] (rid 141623) by ferrieux on 2015-04-24 22:22:37:

    1. closer changed to: "nobody"
    2. icomment:
      Reopening because I think there's still something wrong:
      
       -assume we're doing a kind of "tail -f" (purpose of fleeting EOF) on a file that we opened with encoding utf-8
      
       -assume another process slowly writes to it the subsequent two bytes \xC3 and \xA9 
      
       => our reader gets two subsequent characters "Ã" and "©"
      
       -replay the same scenario but with the two bytes already in, or written fast enough that the reader gets both in one shot
      
       => our reader gets the single char "é"
      
      So it seems that when the fleeting EOF happens in mid-multibyte, the truncated sequence is somehow mapped to a character. Instead, it should be stored in internal state, and no character should be returned until the sequence completes. Easier said than done, I'll admit.
      
    3. login: "ferrieux"
    4. mimetype: "text/plain"
    5. status changed to: "Open"
  21. Ticket change [7ab0c8658e] (rid 141625) by dgp on 2015-04-25 01:54:37:

    1. icomment:
      
      Well these are the dilemmas that arise when we don't
      allow END of file to actually mean it, not aren't they?
      
      The other "purpose of fleeting eof" is the old tcl-udp
      strategy that every packet on a channel is effectively 
      its own file, and terminates with a fleeting eof.
      
      It's an ungodly mess, and the only semi-rational answer
      I can propose at the moment is to restore bugward
      compatibility with 8.5.15.
      
      So sometime soon let's draft the set of tests that demo
      the useful cases, run them against 8.5.15 to get the
      target results and hit them.
      
      Until then, what's on the trunk isn't any more "wrong"
      than any other interpretation.
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  22. Ticket change [366a099e93] (rid 143036) by dkf on 2015-09-06 14:31:38:

    1. login: "dkf"
    2. mimetype: "text/plain"
    3. status changed to: "Pending"
  23. Ticket change [10e8da3c9e] (rid 258144) by serhiy.storchaka on 2026-10-15 11:29:07:

    1. icomment: "Closing: fixed, see above."
    2. login: "serhiy.storchaka"
    3. mimetype: "text/x-fossil-wiki"
    4. status changed to: "Closed"