Skip to content

Handle malformed RFC 2231 continuations in parse_options_header#270

Merged
Kludex merged 13 commits into
Kludex:mainfrom
manunio:fix-bugs-found-by-fuzz
May 17, 2026
Merged

Handle malformed RFC 2231 continuations in parse_options_header#270
Kludex merged 13 commits into
Kludex:mainfrom
manunio:fix-bugs-found-by-fuzz

Conversation

@manunio

@manunio manunio commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • handle both ValueError (oversized RFC 2231 index) and TypeError (mixed continuation forms) from Message.get_params()
  • add regression tests covering oversized index and mixed RFC 2231 continuation inputs to prevent fuzz-found crashes
  • Update cifuzz action for sarif crash fix: cifuzz: handle empty frames in get_error_frame to prevent IndexError google/oss-fuzz#15352
  • A Pre-check for mixed RFC2231 parameter continuations was added as email.message.Message.get_params() handles these maliciously formed headers differently in Python 3.12 vs 3.13

Why

parse_options_header relied on stdlib email parsing that can raise different exception types for malformed parameter continuations. These changes keep existing behavior while making parser failure handling robust and preventing constant fuzzer crashes(improves its performance)

Validation

  • uv run pytest -q
  • uv run ruff check python_multipart/exceptions.py python_multipart/multipart.py tests/test_multipart.py

@manunio manunio changed the title Fix bugs found by fuzz Fix parse_options_header to handle ValueError and TypeError Apr 25, 2026
@Kludex Kludex changed the title Fix parse_options_header to handle ValueError and TypeError Handle malformed RFC 2231 continuations in parse_options_header Apr 25, 2026
@Kludex Kludex changed the title Handle malformed RFC 2231 continuations in parse_options_header Handle malformed RFC 2231 continuations in parse_options_header Apr 25, 2026
@Kludex

Kludex commented Apr 25, 2026

Copy link
Copy Markdown
Owner

Thanks @manunio 🙏

@manunio

manunio commented Apr 25, 2026

Copy link
Copy Markdown
Contributor Author

I’m returning the header as is to avoid regex magic for parser differences between python versions.

@manunio

manunio commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

@Kludex i have also updated the cifuzz action as the fix for oss-fuzz sarif bug was merged recently.

@manunio

manunio commented Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

Hi @Kludex Just checking in to see if there is anything else you need from my side to get this merged.

@Kludex

Kludex commented Apr 28, 2026

Copy link
Copy Markdown
Owner

I don't want the behavior to be different in different Python versions (and I don't think we should use assertIn).

I just noticed the above after checking it properly.

@Kludex

Kludex commented Apr 28, 2026

Copy link
Copy Markdown
Owner

I didn't have time to propose improvements, that's why I went silent here.

…ons and rollbacked the tests for consistent behavior across diff python version.
@manunio

manunio commented Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review, I have update the code and test, so that it stays consistent against diff python version.

@manunio

manunio commented Apr 29, 2026

Copy link
Copy Markdown
Contributor Author

I have been fuzzing the parse_options_header function with the above fix for a few hours on my vps; no issues have been detected so far.

Edit: I’ve now been running this all day with no issues. I think it’s good to go.

@manunio manunio force-pushed the fix-bugs-found-by-fuzz branch from c7c652e to 1ac1269 Compare April 29, 2026 15:27
@manunio

manunio commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

Hi @Kludex, Please review this whenever you're free.

…ME parameters and update parse_options_header to use it
@manunio

manunio commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

I have update the code to handle a false positive edge case(earlier fix was not handelling the the semicolon inside quoted string well).

@codspeed-hq

codspeed-hq Bot commented May 10, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 5 untouched benchmarks


Comparing manunio:fix-bugs-found-by-fuzz (7dc606b) with main (75c33b2)

Open in CodSpeed

@manunio manunio marked this pull request as draft May 14, 2026 18:58
@Kludex Kludex marked this pull request as ready for review May 17, 2026 12:53

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b051895e62

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread python_multipart/multipart.py Outdated
Remove the pre-check and `_split_mime_parameters` helper. The only
cross-version divergence is mixed `filename*` + `filename*0*`
continuations, which raise `TypeError` on 3.12 but return a value on
3.13+. Accept that small inconsistency until 3.12 EOL rather than
maintain a parallel MIME splitter; the `try/except` still covers the
oversized-index `ValueError` on every supported version.

Gate the mixed-continuations test on Python < 3.13 and add a TODO to
drop the `TypeError` arm when 3.12 reaches EOL.

@Kludex Kludex left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manunio Sorry for the delay and back and forth in this PR. Nowadays, given AI, your contributions are the ones that I enjoy the most.

I've thought a bit more about this, and I think the simpler solution you had before was fine - with the tweak that I actually want a path forward for when we drop Python 3.12.

@Kludex Kludex merged commit a60dcdc into Kludex:main May 17, 2026
11 checks passed
@Kludex Kludex mentioned this pull request May 17, 2026
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

Successfully merging this pull request may close these issues.

2 participants