Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2024-08-23
13:30
Merge [054ebbf73b75fd6e]: Fix [c4eb46a1]: endless loop on non blocking gets with encoding error. No ... check-in: 7bfbc78c79 user: pooryorick tags: unchained, INCOMPATIBLE_LICENSE
2023-11-13
16:27 • Ticket [c4eb46a196] endless loop in gets on encoding error in non blocking mode<... artifact: 7f0ae593bc user: oehhar
16:25 • Closed ticket [c4eb46a196]. artifact: b3c7ea141b user: oehhar
16:20 • Ticket [c4eb46a196]: 5 changes artifact: 39d636733e user: oehhar
16:19
Bug [c4eb46a1]: endless loop on non blocking gets with encoding error. No additional failing tests. check-in: 054ebbf73b user: oehhar tags: trunk, main
15:35
Bug [c4eb46a1]: endless loop on non blocking gets with encoding error. Now, tests zlib-8.21 and zlib... check-in: 94257f6465 user: oehhar tags: core-8-branch
12:48
Bug [c4eb46a1]: non-blocking gets fires the error on 2nd call when sequence is incomplete. Added som... closed check-in: dbcafe5259 user: oehhar tags: bug-c4eb46a1
2023-11-12
19:38 • Ticket [c4eb46a196] gets blocks on encoding error in non blocking mode statu... artifact: 0ae3cc285e user: oehhar
19:32
bug [c4eb46a1]: fix was effective for test sequence "A\xC3B", but not for "A\x81". So add test io-75... check-in: 90ac5ff8f7 user: oehhar tags: bug-c4eb46a1
18:55
Bug [c4eb46a1]: endless loop on gets, non blocking, profile strict, encoding error: remove non-block... check-in: 831c9a8797 user: oehhar tags: bug-c4eb46a1
2023-11-06
14:59 • New ticket [c4eb46a196] gets blocks on encoding error in non blocking mode. artifact: 92e6b4ec64 user: oehhar

endless loop in gets on encoding error in non blocking mode

Closed / Fixedc4eb46a196227040bfb18770ac261d6836e58f0eCreated 3 years agoUpdated 3 years ago
Descriptionwiki2023-11-06 14:59:06

Issue

*gets* hangs on a non blocking file channel when an encoding error should be reported.

Example

set f [open test_A_195_B.txt wb]; puts -nonewline $f A\xC3B; close $f
set f [open test_A_195_B.txt r]
fconfigure $f -encoding utf-8 -profile strict -blocking 0
gets $f

A file is created with a non continued UTF-8 multi-byte sequence. The channel is configured to error out on encoding errors. Then, a gets in non-blocking mode is executed.

TCL hangs on the *gets* line.

Environment

  • Branch: core-8-branch, tip-653
  • System: Windows 10 64 bit GER
  • Compiler: MS-VS 2015 on 32 bit

Thank you all ! Harald

oehharwiki2023-11-12 19:38:27

A debugging session showed an endless loop in tclIO.c. The wihile-loop in line 4750 was never exited.

The exit-point of the blocking case was explicitly excempted for the non blocking case. Line 4920 reads:

	} else if (gs.bytesWrote == 0
		&& GotFlag(statePtr, CHANNEL_ENCODING_ERROR)
		&& !GotFlag(statePtr, CHANNEL_NONBLOCKING)) {
	    /* Set eol to the position that caused the encoding error, and then
	     * continue to gotEOL, which stores the data that was decoded
	     * without error to objPtr.  This allows the caller to do something
	     * useful with the data decoded so far, and also results in the
	     * position of the file being the first byte that was not
	     * successfully decoded, allowing further processing at exactly that
	     * point, if desired.
	     */
	    eol = dstEnd;
	    goto gotEOL;
	}

Removing the condition for NONBLOCKING cures the endless loop.

Commit [831c9a8797] in branch bug-c4eb46a1 implements this with an added test.

This is successful for the error sequence "A_195_B" (as described above). Unfortunately, it is not successful for the error sequence "A\x81", what is used in the original test io-75.6. In this case, the gets returns successfully without error message.

So, two tests were added for both cases (io76.6.1 and io-76.6.2) with commit [90ac5ff8f7].

oehharwiki2023-11-13 16:20:20

It is also effective for the 2nd error sequence. The 2nd error sequence is an incomplete UTF-8 sequence. Then, the end of file will trigger the error, which is reached by a second "gets" command.

The test is adopted to this double "gets".

An additional test to check the recovery capabilities is added. There, the encoding is changed to binary and the gets succeeds.

The branch is merged to core-8-branch by commit [94257f6465].

Now, two new tests fail, which looks unrelated:

==== zlib-8.21 zlib transformation, bug f9eafc3886 FAILED
==== Contents of test case:

    set f [zlib push gzip [open $file w] -header [list comment \u100]]

---- Test completed normally; Return code was: 0
---- Return code should have been one of: 1
==== zlib-8.21 FAILED

---- zlib-8.22 start


==== zlib-8.22 zlib transformation, bug f9eafc3886 FAILED
==== Contents of test case:

    set f [zlib push gzip [open $file w] -header [list filename \u100]]

---- Test completed normally; Return code was: 0
---- Return code should have been one of: 1
==== zlib-8.22 FAILED

I may do another debugger session to find out why.

But the endless loop is cured, which is more important than a failing test.

oehharwiki2023-11-13 16:25:52

Merged to main with commit [054ebbf73b]. No additional failing tests. So, closing this ticket.

Thank you all, Harald

oehhar Ticket [c4eb46a196]: 4 changes [History diff]2023-11-13 16:27:52
Log in (anonymous is fine) to add a comment.