Repository navigation
Fix segfault in add() with a keyword-only required argument - #1376
Conversation
parse2() (the two-argument FASTCALL parser) did not enforce minargs in its keyword branch: a call like MultiDict().add(key='k') left the second argument as a NULL pointer, which the caller dereferenced and segfaulted. It also mis-routed calls with more than two keyword arguments into the one-keyword path. Enforce minargs when the sole supplied argument is passed by keyword (raise the same 'missing required argument' TypeError as the pure-Python fallback), and reject >2 keyword arguments with an 'unexpected keyword argument' error. Adds a parity regression test over both implementations.
There was a problem hiding this comment.
@devdanzin The workflows seem to fail along with a segfault my recommendation would be to go through the code carefully. Sometimes I tend to do is use print statements to track where the segfault occurred letting me have real time feedback without needing to bruteforce. When I am done I clear all the print statements I have made and then push the new commit when completed.
Confidence Score: 5/5No blocking failure remains; the native parser builds cleanly and handles the covered invalid and valid keyword call forms correctly. No accepted P0 or P1 findings remain after the native build, compiler-warning, runtime, and focused regression checks. Reviews (4): Last reviewed commit: "[pre-commit.ci] auto fixes from pre-comm..." | Re-trigger Greptile |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1376 +/- ##
=======================================
Coverage 99.86% 99.86%
=======================================
Files 29 29
Lines 3744 3756 +12
Branches 279 279
=======================================
+ Hits 3739 3751 +12
Misses 3 3
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@aiolibsbot rr |
PR Review — Fix segfault in
|
|
The summary is accurate. The remaining items are worthwhile but non-blocking: move the |
Rebase with requested adjustmentsBranch Changes applied
Not changed (and why)
StatsActions performed
CI statusCI will be checked asynchronously. Automated by Kōan |
|
The advertised follow-up adjustments are not present in the revision under review. The PR currently reports 3 changed files and 52 additions, while the description says 4 files and 70 additions. In particular:
Please push the commit containing those adjustments (or update the description); the parser fix itself is present, but I cannot verify the requested test and news-fragment changes from this revision. |
|
Thanks, @devdanzin ! |
What do these changes do?
MultiDict().add(key="k")— a required argument supplied only by keyword, with the other missing —segfaulted the interpreter instead of raising
TypeError. The two-argument FASTCALL parserparse2()(
_multilib/parser.h) did not enforceminargsin its keyword branch, sovaluereached the caller asa NULL pointer that was then dereferenced. Calls with more than two keyword arguments were also
mis-routed into the one-keyword path.
parse2()now enforcesminargswhen the only supplied argument comes by keyword, and rejectsmore-than-two keyword arguments. The pure-Python backend already raised the correct
TypeErrors forthese calls, so this only brings the C extension in line — no pure-Python change is needed.
Are there changes in behavior for the user?
Yes:
MultiDict().add(key="k")andadd(key="k", value="v", extra="e")now raiseTypeError(the samemessages the pure-Python implementation raises) instead of crashing / silently misbehaving.
Is it a substantial burden for the maintainers to support this?
No. A localized fix in one argument-parser function, plus a parametrized regression test.
Related issue number
Same argument-parser family as the
setdefault()segfault #1159 (fixed narrowly by #1160);add()wasstill affected. Surfaced by the C-extension analysis report #1306.
Checklist
test_add_missing_required_argument, both backends)CONTRIBUTORS.txtin this repoCHANGES/folder