coolaj86 / formaline

formaline is a module for handling form requests ( HTTP POSTs / PUTs ) and for fast parsing of file uploads.
Apache License 2.0
239 stars 16 forks source link

upload fails when quickparser return null array #27

Closed lonevan closed 11 years ago

lonevan commented 13 years ago

Hi rootslab ,

I tried formaline(latested version) for img upload, but got fails sometimes. I have lookuped the issues, found someone have the same problem. I use express(2.4.3) for web framework, so I considerd express at first, cause I tried the example,it works fine. But when I use express directly without middlewares, formaline also works well. Finally I found there's something wrong when I using connect-mongostore as session store(memory or null session ok too), but I don't know why.

I debugged the code, found quickparser return [] while upload failed. here's the chunk:

<Buffer 45 12 cd 23 a4 60 8c b6 7f 0a 59 f5 30 27 66 79 0b ca e7 6e 43 67 f3 ae 8c 06 06 72 8f 32 a8 ad e6 ac fe 67 3f d5 92 4e e8 e3 ad bc 39 a9 6a 28 43 db 08 95 8f ca 49 c6 3d aa c6 a9 e1 1b ed 3f 4b 7b 99 2e 2d 25 7c 83 b1 4b 65 47 7c 9a eb 5e fd c8 c9 77 0b ec 47 15 7a 2b 91 2d ac 90 cf 39 9e 27 e9 b8 e0 ff 00 fa ab b7 19 96 46 d7 4f de f4 d0 e8 86 55 4a ce 3b be 8f 63 c3 9a d5 e3 2b 24 a7 0f 9c 6d 07 38 a8 98 2c a7 60 89 c1 ce 3... too long to parse

lonevan commented 13 years ago

and the debug Info: =========================this is ok================================= -> req url : /test/upload formaline, a session ID string was found : "tmp" formaline, upload root dir exists: "/tmp/" formaline, upload subdirectory already exists : "/tmp/tmp/" formaline, HTTP Request Headers : { "host": "www.xxx.com:3000", "connection": "keep-alive", "referer": "http://www.xxx.com:3000/test/", "content-length": "544802", "cache-control": "max-age=0", "origin": "http://www.xxx.com:3000", "user-agent": "Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.100 Safari/534.30", "content-type": "multipart/form-data; boundary=----WebKitFormBoundarylxWIiZdmAkp2y5v1", "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8", "accept-encoding": "gzip,deflate,sdch", "accept-language": "zh-CN,zh;q=0.8", "accept-charset": "GBK,utf-8;q=0.7,*;q=0.3", "cookie": "ccuid=%E9%BE%99%E8%B4%B0%E6%98%AF2B%E7%9A%84%E8%B4%B0; ccuid=%E9%BE%99%E8%B4%B0%E6%98%AF2B%E7%9A%84%E8%B4%B0; connect.sid=cIhNrccYHXubnYcDTH3x3Cqv.KkuYGhnpwVWwm1AGxfm0BqnC40MGiEui%2B2rA4lGXS9g; ccsid=wyHs8C76kZSRYXY842pHXZRM.JMc5yxBdBMuRY96vfMuRL2NMy686vIy8yoOpkrFRG9U" } formaline, new data chunk received, request paused ..
formaline, event "loadstart" --> {"time":1319724580726}
formaline, ( multipart/form-data ) chunk --> {"index":1,"bytes":11228,"results":[{"start":0,"finish":93},{"start":99,"finish":242}]} formaline, parser results length --> 2, chunk #: 1 ... ...

===========================this is fails================================= -> req url : /test/upload formaline, a session ID string was found : "tmp" formaline, upload root dir exists: "/tmp/" formaline, upload subdirectory already exists : "/tmp/tmp/" formaline, HTTP Request Headers : { "host": "www.xxx.com:3000", "connection": "keep-alive", "referer": "http://www.xxx.com:3000/test/", "content-length": "544802", "cache-control": "max-age=0", "origin": "http://www.xxx.com:3000", "user-agent": "Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.100 Safari/534.30", "content-type": "multipart/form-data; boundary=----WebKitFormBoundaryqmUXEs3ySIB5BCMB", "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8", "accept-encoding": "gzip,deflate,sdch", "accept-language": "zh-CN,zh;q=0.8", "accept-charset": "GBK,utf-8;q=0.7,*;q=0.3", "cookie": "ccuid=%E9%BE%99%E8%B4%B0%E6%98%AF2B%E7%9A%84%E8%B4%B0; ccuid=%E9%BE%99%E8%B4%B0%E6%98%AF2B%E7%9A%84%E8%B4%B0; connect.sid=cIhNrccYHXubnYcDTH3x3Cqv.KkuYGhnpwVWwm1AGxfm0BqnC40MGiEui%2B2rA4lGXS9g; ccsid=wyHs8C76kZSRYXY842pHXZRM.JMc5yxBdBMuRY96vfMuRL2NMy686vIy8yoOpkrFRG9U" } formaline, new data chunk received, request paused ..
formaline, event "loadstart" --> {"time":1319724587020}
formaline, ( multipart/form-data ) chunk --> {"index":1,"bytes":22611,"results":[]} formaline, parser results length --> 0, chunk #: 1 formaline, resuming request .. formaline, new data chunk received, request paused ..
formaline, ( multipart/form-data ) chunk --> {"index":2,"bytes":40636,"results":[]} formaline, parser results length --> 0, chunk #: 2

=========================the chunk can't match bondary string===========================

Hope for help~~

coolaj86 commented 11 years ago

PoorForm, upon which Formaline 2.0.0 is built has undergone extensive chunk and boundary checking (and uses QAP, the successor to QuickParser).

It's not guaranteed perfect yet (only because the real world gives test cases that tests can't), but it should have fixed this issue.