fukamachi / fast-http

A fast HTTP request/response parser for Common Lisp.
343 stars 37 forks source link

http-multipart-parse fail at uploading DOS text file #36

Closed odahideo closed 6 years ago

odahideo commented 6 years ago

Hi. I found a problem when I was sending a DOS text file to the ningle/clack/lack server. when the last line of the DOS file is only a pair of #\Return #\Newline, and it is sent by "multipart/form-data" post, the end of post contents are below:

--<boundary text>
<some text>#\Return #\Newline
<some text>#\Return #\Newline
#\Return #\Newline
--<boundary text>--

When 'http-multipart-parse' reads the last part of the contents, the inner state changes like below:

+looking-for-delimiter+ #\Return
+maybe-delimiter-start+ #\Newline
+maybe-delimiter-first-dash+ #\Return
+looking-for-delimiter+ #\Newline
+looking-for-delimiter+ #\-
+looking-for-delimiter+ #\-

It indicates'http-multipart-parse' losts the start of the boundary text. So I tried patching 'src/multipart-parser.lisp':

line 231 from:

                (+maybe-delimiter-first-dash+
                (if (= byte +dash+)
                    (go-state +maybe-delimiter-second-dash+)
                    (go-state +looking-for-delimiter+)))

to:

              (+maybe-delimiter-first-dash+
                (if (= byte +dash+)
                    (go-state +maybe-delimiter-second-dash+)
            (if (= byte +cr+)
            (go-state +maybe-delimiter-start+)
            (go-state +looking-for-delimiter+))))

I think it works well.

thanks.

odahideo commented 6 years ago

I'm sorry. took mistake. Change "to:" code with below:

               (+maybe-delimiter-first-dash+
                (if (= byte +dash+)
                    (go-state +maybe-delimiter-second-dash+)
            (if (= byte +cr+)
            (progn
              (setf (ll-multipart-parser-boundary-mark parser) p)
              (go-state +maybe-delimiter-start+))
            (go-state +looking-for-delimiter+))))
fukamachi commented 6 years ago

Thanks and your patch LGTM. I can merge it if you'll send it as a PR.