Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing does not Terminate #25

Closed
taiseiKMC opened this issue Dec 20, 2021 · 2 comments
Closed

Parsing does not Terminate #25

taiseiKMC opened this issue Dec 20, 2021 · 2 comments

Comments

@taiseiKMC
Copy link

When a requested body is incomplete, Multipart_form.parse sometimes seems to go into an infinite loop

I tried this below code in Multipart_form:v0.3.0

let req =
  {|--------------------------eb790219f130e103
Content-Disposition: form-data; name="text"

default
--------------------------eb790219f130e103
Content-Disposition: form-data; name="file1"; filename="a.html"
Content-Type: text/html

<!DOCTYPE html><title>Content of a.html.</title>

--------------------------eb790219f130e103
Content-Disposition: form-data; name="file2"; filename="a.txt"
Content-Type: text/plain

Conten|}

let run =
  let content_type = Result.get_ok @@ Multipart_form.Content_type.of_string
       "multipart/form-data; \
        boundary=------------------------eb790219f130e103\r\n" in
  let body_stream = Lwt_stream.return req in
  let `Parse th, _ = Multipart_form_lwt.stream ~identify:(fun a -> ()) body_stream content_type in
  Lwt.bind th (fun res -> (match res with | Ok _ -> () | Error (`Msg str) -> failwith str); Lwt.return_unit)

let () = Lwt_main.run run
@dinosaure
Copy link
Owner

Hmmhmm, I can look more closely but it seems that you example was truncated - and it did not finish with the expected end-of-boundary.

But yeah, the process should not do an infinite loop and it should have a mechanism to stop and return an error at least. Currently, we found a bug about that on the mrmime parser too and I did not (yet) patch-back into this library.

Then, I'm currently on vacation but I will look this bug in few weeks. Thanks for your report.

@dinosaure
Copy link
Owner

dinosaure commented Dec 30, 2021

Fixed by #27 🎉

dinosaure added a commit to dinosaure/opam-repository that referenced this issue Jan 27, 2022
CHANGES:

- Split the distribution into two packages: `multipart_form{,-lwt}` (@dinosaure, @leviroth, dinosaure/multipart_form#23)
- Documentation about `Content-Type` (@dinosaure, dinosaure/multipart_form#24)
- Upgrade the distribution with few new releases (@dinosaure, dinosaure/multipart_form#24)
- Add a test about the lwt support (@dinosaure, @taiseiKMC, dinosaure/multipart_form#25, dinosaure/multipart_form#27)
- Allow filenames with space (@dinosaure, @aantron, @cemerick, dinosaure/multipart_form#28)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants