<i>zlib transform issue, multi-stream inflate ignores streams after first</i>.
by
.
D 2020-04-16T05:45:24.171
J assignee nobody
J closer nobody
J cmimetype text/x-fossil-wiki
J comment This\sis\sa\sfollowup\sto\sticket\s[8af92dfb668b292a7b21df9ac0418e3bc2e68be].\r\n\r\nWith\sthat\sissue\sfixed\sthe\sfollowing\sscenario\swas\stried:\r\n\r\n\s\s-\s`cat\sexample.deflated\sexample.deflated\s>\sexample.multi-stream`.\r\n\s\s\s\sThe\sresult\sfile\scontains\stwo\sseparate\szlib\sdeflate\sstreams.\r\n\r\n\s\s-\sModified\sexample.tcl\sto\sread\sthis\sfile,\sand\sto\sattempt\sextraction\sof\sboth\sstreams.\r\n\r\n<pre>\r\nproc\sinflate-transform\s{a\sb}\s{\r\n\s\s\s\sset\sa\s[open\s$a\srb]\r\n\s\s\s\sset\sb\s[open\s$b\swb]\r\n\s\s\s\sputs\sI/O.0:[tell\s$a]/[tell\s$b]\r\n\s\s\s\szlib\spush\sinflate\s$a\r\n\s\s\s\sputs\sC:[fconfigure\s$a]\r\n\s\s\s\sfcopy\s$a\s$b\r\n\s\s\s\sputs\sI/O.1:[tell\s$a]/[tell\s$b]\r\n\s\s\s\schan\spop\s$a\r\n\s\s\s\sputs\sI/O.2:[tell\s$a]/[tell\s$b]\r\n\s\s\s\szlib\spush\sinflate\s$a\r\n\s\s\s\sfcopy\s$a\s$b\r\n\s\s\s\sputs\sI/O.3:[tell\s$a]/[tell\s$b]\r\n\s\s\s\schan\spop\s$a\r\n\s\s\s\sputs\sI/O.4:[tell\s$a]/[tell\s$b]\r\n\s\s\s\sclose\s$a\r\n\s\s\s\sclose\s$b\r\n\s\s\s\sreturn\r\n}\r\n</pre>\r\n\r\nThe\sresult:\r\n\r\n\s\s-\sFirst\sstream\sextracted\sok\r\n\r\n\s\s-\sSecond\sstream\swas\signored\s(skipped\sover\swhen\sreading\sthe\sfirst\sstream).\r\n\r\nInvestigation\sof\s`ZlibTransformInput`\sand\sits\ssubordinate\s`ResultGenerate`\sshows\sthat\swhile\s`RG`\sproperly\sdetects\sthe\sstream\send\sthis\scondition\sis\snot\ssignaled\sto\sits\sparent\s`ZTI`,\swhich\sproceeds\sto\scontinue\sreading\sfrom\sthe\sunderlying\sstream\suntil\sit\shits\sthe\sunderlying\sEOF,\swhile\snever\swriting\smore\sto\sthe\soutput.\sIOW\sit\seffectively\sskips\sall\sdata\safter\sthe\sfirst\sstream.\r\n\r\nAfter\sthe\sextraction\sof\sthe\sfirst\sstream\sthe\sunderlying\schannel\sis\sat\sits\sEOF,\sand\sthe\ssecond\sstream\scannot\sbe\sextracted\sanymore.\r\n\r\nThe\spatch\r\n\r\n<pre>\r\nIndex:\sgeneric/tclZlib.c\r\n==================================================================\r\n---\sgeneric/tclZlib.c\r\n+++\sgeneric/tclZlib.c\r\n@@\s-126,10\s+126,12\s@@\r\n\s\s\s\s\sTcl_TimerToken\stimer;\t/*\sTimer\sused\sfor\skeeping\sevents\sfresh.\s*/\r\n\s\s\s\s\sTcl_DString\sdecompressed;\t/*\sBuffer\sfor\sdecompression\sresults.\s*/\r\n\s\s\s\s\sTcl_Obj\s*compDictObj;\t/*\sByte-array\sobject\scontaining\scompression\r\n\s\t\t\t\t\s*\sdictionary\s(not\sdictObj!)\sto\suse\sif\r\n\s\t\t\t\t\s*\snecessary.\s*/\r\n+\s\s\s\sint\sdone;\t\t\t/*\sFlag\sto\ssignal\sstream\send\sup\sto\stransform\r\n+\t\t\t\t\s*\sinput\s*/\r\n\s}\sZlibChannelData;\r\n\s\r\n\s/*\r\n\s\s*\sValue\sbits\sfor\sthe\sflags\sfield.\sDefinitions\sare:\r\n\s\s*\tASYNC\s-\t\tWhether\sthis\sis\san\sasynchronous\schannel.\r\n@@\s-3011,10\s+3013,14\s@@\r\n\s\tgotBytes\s+=\scopied;\r\n\s\r\n\s\tif\s(toRead\s==\s0)\s{\r\n\s\t\s\s\s\sreturn\sgotBytes;\r\n\s\t}\r\n+\r\n+\tif\s(cd->done)\s{\r\n+\t\s\s\s\sreturn\sgotBytes;\r\n+\t}\r\n\s\r\n\s\t/*\r\n\s\t\s*\sThe\sbuffer\sis\sexhausted,\sbut\sthe\scaller\swants\seven\smore.\sWe\snow\r\n\s\t\s*\shave\sto\sgo\sto\sthe\sunderlying\schannel,\sget\smore\sbytes\sand\sthen\r\n\s\t\s*\stransform\sthem\sfor\sdelivery.\sWe\smay\snot\sget\swhat\swe\swant\s(full\sEOF\r\n@@\s-3831,10\s+3837,13\s@@\r\n\s\t\s*/\r\n\s\r\n\s\tif\s(((flush\s==\sZ_SYNC_FLUSH)\s&&\s(e\s==\sZ_BUF_ERROR))\r\n\s\t\t||\s(e\s==\sZ_STREAM_END)\r\n\s\t\t||\s(e\s==\sZ_OK\s&&\swritten\s==\s0))\s{\r\n+\t\s\s\s\sif\s(e\s==\sZ_STREAM_END)\s{\r\n+\t\tcd->done\s=\s1;\r\n+\t\s\s\s\s}\r\n\s\t\s\s\s\sreturn\sTCL_OK;\r\n\s\t}\r\n\s\r\n\s\t/*\r\n\s\t\s*\sZ_BUF_ERROR\scan\sbe\signored\sas\sper\shttp://www.zlib.net/zlib_how.html\r\n</pre>\r\n\r\nsolved\sthat\sissue.\sA\snew\sflag\sto\scapture\sthe\sstream\seof\scondition,\ssetting\sit\sat\sthe\sappropriate\splace,\sand\sa\scheck\sin\sthe\scaller\sto\sabort\sbuffer\sfilling\swhen\sreaching\sstream\send.\r\n\r\nAt\sthis\spoint\swe\scan\sthen\salso\sdemonstrate\sthat\ssetting\s`-limit`\sto\sa\svalue\s>\s1\scauses\sthe\ssecond\sstream\sto\sbe\seither\signored,\sor\sto\sgenerate\san\serror\son\strying\sto\sread\sit.\sIt\sis\signored\sif\sthe\s`-limit`\swas\slarge\senough\sto\sskip\sover\sthe\sentire\sstream.\sAn\serror\shappens\sif\sthe\s2nd\sstream\swas\spartially\sread\swhile\sprocessing\sthe\send\sof\sthe\sfirst,\scausing\szlib\sto\ssee\ssomething\swhich\sis\snot\sa\svalid\sstream\sanymore.\r\n\r\nStopping\shere.\sHave\sto\sinvestigate\snow\sif\sit\sis\spossible\sto\sdetermine\swhich\sparts\sof\sthe\sunderlying\sstream\sare\sread\sand\snot\sprocessed\sby\szlib,\sand\sthen\sif\sit\sis\spossible\sto\sstash\sthat\spart\sback\sfor\sthe\snext\stransformation,\sor\sjust\sthe\splain\schannel.
J foundin 8.6.10
J is_private 0
J login aku
J priority 5\sMedium
J private_contact 194c9ef8edbd9a57ef36f4f18fde1d57ce26e1e5
J resolution None
J severity Critical
J status Open
J submitter aku
J subsystem 57.\szlib
J title zlib\stransform\sissue,\smulti-stream\sinflate\signores\sstreams\safter\sfirst
J type Bug
K f70ce1feadf55c2f0fd142bdc20fbdcae5698495
U aku
Z eb40042f8b874d22ecbd68cfac5b1674