Skip to content
Tcl Source Code Artifact [0f26611a0c]
Login

Artifact [0f26611a0c]

Artifact 0f26611a0c523317b1a050d9057b068baf0d3daa:

Manifest of check-in [0f26611a0c] - Fixed a tricky interaction of IO system and encodings which could result in a panic. The relevant function is ReadChars() (short RC in the following). When the encoding and translation transforms deliver more characters than were requested the iterative algorithm used by RC reduces the value of "dstLimit" (= the number of bytes allowed to be copied into the destination buffer) to force the next round to deliver less characters, hopefully the number requested. The existing code used the byte located just after the last wanted character to determine the new limit. The resulting value could _undershoot_ the best possible limit because Tcl_ExternalToUtf would effectively reduce this limit further, by TCL_UTF_MAX+1, to have enough space for a single multi-byte character in the buffer, and a closing '\0' as well. One effect of this were additional calls to ReadChars() to retrieve the characters missed by a call with an undershot limit. In the limit (sic) however this was also able to cause a full-blown "Buffer Underflow" panic if the original request was for less than TCL_UTF_MAX characters (*), and we are using a single-byte encoding like iso-8859-1. Because then the undershot dstLimit would prevent the next round from copying anything, and causing it to try and consolidate the current buffer with the next buffer, thinking that it had to merge a multi-byte character split across buffer boundaries. (Ad *) For example because the previous call had undershot already and left only such a small amount of characters behind! The basic fix to the problem is to add TCL_UTF_MAX back to the limit, like is done in all the (three) other places in RC setting a new one. Note however that this naive fix may generate a new limit which is the same as the old, or possibly larger. If that happens we act very conservatively and reduce the limit by only one byte instead. While I believe that this last conservative approach will never reduce the limit to TCL_UTF_MAX or less before reaching a state where it returnds the exact amount of requested characters I still added a check against this situation anyway, causing a new panic if triggered. by andreask on 2014-06-05 00:22:59.
B 5145f9b67365b976e0cfb48ee865aa77d8cd336d
C Fixed\sa\stricky\sinteraction\sof\sIO\ssystem\sand\sencodings\swhich\scould\nresult\sin\sa\spanic.\n\nThe\srelevant\sfunction\sis\sReadChars()\s(short\sRC\sin\sthe\sfollowing).\n\nWhen\sthe\sencoding\sand\stranslation\stransforms\sdeliver\smore\scharacters\nthan\swere\srequested\sthe\siterative\salgorithm\sused\sby\sRC\sreduces\sthe\nvalue\sof\s"dstLimit"\s(=\sthe\snumber\sof\sbytes\sallowed\sto\sbe\scopied\sinto\nthe\sdestination\sbuffer)\sto\sforce\sthe\snext\sround\sto\sdeliver\sless\ncharacters,\shopefully\sthe\snumber\srequested.\n\nThe\sexisting\scode\sused\sthe\sbyte\slocated\sjust\safter\sthe\slast\swanted\ncharacter\sto\sdetermine\sthe\snew\slimit.\sThe\sresulting\svalue\scould\n_undershoot_\sthe\sbest\spossible\slimit\sbecause\sTcl_ExternalToUtf\swould\neffectively\sreduce\sthis\slimit\sfurther,\sby\sTCL_UTF_MAX+1,\sto\shave\nenough\sspace\sfor\sa\ssingle\smulti-byte\scharacter\sin\sthe\sbuffer,\sand\sa\nclosing\s'\\0'\sas\swell.\n\nOne\seffect\sof\sthis\swere\sadditional\scalls\sto\sReadChars()\sto\sretrieve\nthe\scharacters\smissed\sby\sa\scall\swith\san\sundershot\slimit.\n\nIn\sthe\slimit\s(sic)\showever\sthis\swas\salso\sable\sto\scause\sa\sfull-blown\n"Buffer\sUnderflow"\spanic\sif\sthe\soriginal\srequest\swas\sfor\sless\sthan\nTCL_UTF_MAX\scharacters\s(*),\sand\swe\sare\susing\sa\ssingle-byte\sencoding\nlike\siso-8859-1.\sBecause\sthen\sthe\sundershot\sdstLimit\swould\sprevent\sthe\nnext\sround\sfrom\scopying\sanything,\sand\scausing\sit\sto\stry\sand\nconsolidate\sthe\scurrent\sbuffer\swith\sthe\snext\sbuffer,\sthinking\sthat\sit\nhad\sto\smerge\sa\smulti-byte\scharacter\ssplit\sacross\sbuffer\sboundaries.\n\n(Ad\s*)\sFor\sexample\sbecause\sthe\sprevious\scall\shad\sundershot\salready\sand\nleft\sonly\ssuch\sa\ssmall\samount\sof\scharacters\sbehind!\n\nThe\sbasic\sfix\sto\sthe\sproblem\sis\sto\sadd\sTCL_UTF_MAX\sback\sto\sthe\slimit,\nlike\sis\sdone\sin\sall\sthe\s(three)\sother\splaces\sin\sRC\ssetting\sa\snew\none.\sNote\showever\sthat\sthis\snaive\sfix\smay\sgenerate\sa\snew\slimit\swhich\nis\sthe\ssame\sas\sthe\sold,\sor\spossibly\slarger.\sIf\sthat\shappens\swe\sact\nvery\sconservatively\sand\sreduce\sthe\slimit\sby\sonly\sone\sbyte\sinstead.\n\nWhile\sI\sbelieve\sthat\sthis\slast\sconservative\sapproach\swill\snever\sreduce\nthe\slimit\sto\sTCL_UTF_MAX\sor\sless\sbefore\sreaching\sa\sstate\swhere\sit\nreturnds\sthe\sexact\samount\sof\srequested\scharacters\sI\sstill\sadded\sa\ncheck\sagainst\sthis\ssituation\sanyway,\scausing\sa\snew\spanic\sif\striggered.\n
D 2014-06-05T00:22:59.614
F doc/clock.n 023a904fb915554eb6e6936d5955a0fdc4d5c6b5
F doc/tclvars.n d52d78df61edd63d3e0ed0bc1999468a207fb1f1
F generic/tcl.h f522f635046f5c9bc74cc910bf1938605286f23a
F generic/tclBasic.c ca0d96f141cb6d528010f7ae398349cf23f55fdf
F generic/tclBinary.c 9314bc3cf9ab1c98f46e83c75da6384b130040b3
F generic/tclClock.c 8f3cf95158c4dccfdc40e3c83b9e0792de84f480
F generic/tclCmdMZ.c 4183bf30eaaac3190f24bf61e6a34867a843cc05
F generic/tclEncoding.c 526a506b8b74b08c8de83a03a2938e87e32e903c
F generic/tclExecute.c e102ceaf11705fa8d2f62434280aab033f0efb4f
F generic/tclIO.c ed43cda0b4c9ec005abde57761ee392991ebe1ec
F generic/tclIO.h 8048ce39af8db4c1565a686e5dab72941124d574
F generic/tclIOCmd.c 2a8c84d46a3793ddf8399440cf617469d5ae1201
F generic/tclIOGT.c 511ad3ee065b65907c101047832fd15b515bf72e
F generic/tclIORChan.c 8fc888c9643b48014a6f2356020e9eded5336e6e
F generic/tclIOUtil.c a18beadc89b1263f22af636c58316dad93865754
F generic/tclInt.h 646709dfd60b94a3b58cd9c6eca98b30999d15e4
F generic/tclIntPlatDecls.h 899328427806c04696716f96508f8072c0740f1b
F generic/tclListObj.c 3d0412775d3d200eab6a159b2e2087ad23990c5d
F generic/tclNotify.c bada4bc2f860758a60810040513c06f10d53e06a
F generic/tclStringObj.c a91bcd6ae1a75bbb790046fd0bd4c4c9d1b8d520
F generic/tclStubInit.c 6d9b87d340fd0e6c8a859180102442b9a5b4d007
F generic/tclThread.c df1432c407465c97b02ea58a38bfb97245f8ef8c
F generic/tclThreadAlloc.c f08799faafc9147a4b9cd020a1ef15b7ede3d4ae
F generic/tclUtil.c 6db0377f7604898af56bc3e4d4c43baec70ca262
F library/init.tcl 3d9a25f97686734bbf55d3a13388165c12c348d4
F library/parray.tcl a0b1bd4e68dce1768d3c5e0d3c7b31e28021d3ba
F library/tcltest/pkgIndex.tcl 045ecb9e24608694c6ec88d252012239c6dd6b73
F library/tcltest/tcltest.tcl 0026f9e0fea4c0538515690a618a5ffd378c865e
F tests/chanio.test b4812e705a73b4daba34d7e06c9f62a8d3dda20a
F tests/clock.test 530f4af8e558467725ef42ffd9dff83958add128
F tests/cmdAH.test 56d5d88f42eb60b01d37d42cc5dd01f6add6230a
F tests/io.test bc216180812f81d52035ac442bd8d661c8cdf18c
F tests/ioCmd.test c5f409c87a5347e637f26aa8dda2b246577b8b31
F tests/iogt.test e7b2954b68522fe9f98033b16f9fd9cc32fa15b3
F tests/namespace.test 96bd1d62b1c7f86f462a87c76492b7605783a703
F tests/socket.test 8269635d838903564187738adb968829ecfdcc3c
F unix/Makefile.in 0805adfef4a451ea77f143f0cc3b396b11340fd9
F unix/configure 4ef908e29a7a191a44017afb1faa10f37b98ce9a x
F unix/configure.in b9dcace895517bd0c915569cf867f864a00ba2bb
F unix/tcl.m4 48c8e37603b1fea17af7373ca91b5d3b1d1e639b
F unix/tcl.pc.in ec0d5900f48812f8a743be3f9d9982bf49a1c949
F unix/tclConfig.sh.in 6c2f3bf7285bc8ae34a86fbb03abf13554cea428
F unix/tclUnixFile.c d9e27b7216ba9869dce5f512073701b0a9615402
F unix/tclUnixInit.c 0482cc7eb84bec324530730b02751c40ba88def3
F unix/tclUnixThrd.c 479aec97fdbd8220a6a47fed0ec9fd0848de002c
F win/Makefile.in ba4b95ea49dffdfe311164922f95c0e21e30f487
F win/configure 6796c6d081cd7913a5c2708e4146f26f9bd4df77 x
F win/configure.in 514a64b85283699f518998638c289afd1d9273b2
F win/makefile.vc 452223f7f2fc94392fcbc685d15274b58c624220
F win/tclConfig.sh.in 981fb036808da6e05a9be59368c8e133232deb91
F win/tclWin32Dll.c 40b0bec3e0e2bf6c89ed8ba6768ce84f57e2fb78
F win/tclWinChan.c a288fcf8f36fe3166a3be276200b93b41eb56afd
F win/tclWinFCmd.c 460b98be326f72ebef1056fa81c53cd7f5398287
F win/tclWinFile.c 4509f674d121f0d4d4bc2277549306358cda91cd
F win/tclWinInit.c baf7cf154946ad2cd027824703799e443e1fa943
F win/tclWinInt.h b6afacd04337b999218a18d79791fcee6b112501
F win/tclWinPort.h 47c9f0469d202c5aa04e5d29f1fe22f78319d000
F win/tclWinSerial.c d18f2a14fba23d937887106b398904c20013fc06
F win/tclWinSock.c dd80d30e5bd9c0d83973e71c09f7f4cb3e3ce84c
F win/tclsh.exe.manifest.in 11f0700eb0759f46f6c3a3a51ae529698a122d8d
F win/tclsh.rc 967eeedb2ed14f07b6e59294a0f9a0e63ee0d8fd
P 2b1cda088c81c9d88fc056d31b188f75bbca9401
R d359f09c2d558aef8a1eaaa84246e68e
U andreask
Z 0af763240ed81a06978b9ce8a60d328a