Fix IndexError in parse_content_disposition when param value is empty#12948
Open
JSap0914 wants to merge 1 commit into
Open
Fix IndexError in parse_content_disposition when param value is empty#12948JSap0914 wants to merge 1 commit into
JSap0914 wants to merge 1 commit into
Conversation
When a Content-Disposition header parameter has an empty value
(e.g. "attachment; filename="), the is_quoted() helper raised
IndexError: string index out of range because it indexed string[0]
on an empty string without a length guard.
Add a len(string) >= 2 guard before indexing, consistent with the
minimum requirement for a quoted-string (two quote characters).
Fixes the crash; the function now emits BadContentDispositionHeader
and returns (None, {}) as expected for malformed headers.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #12948 +/- ##
=======================================
Coverage 98.95% 98.95%
=======================================
Files 131 131
Lines 47998 48008 +10
Branches 2494 2494
=======================================
+ Hits 47498 47508 +10
Misses 376 376
Partials 124 124
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Merging this PR will not alter performance
Comparing Footnotes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
parse_content_dispositionraises an unhandledIndexError: string index out of rangewhen aContent-Dispositionheader contains a parameter with an empty value, such as:The inner helper
is_quotedindexesstring[0]without first checking that the string is non-empty:Fix
Added a
len(string) >= 2guard before indexing — a quoted-string requires at minimum two characters (the opening and closing").The function now correctly warns with
BadContentDispositionHeaderand returns(None, {})for this malformed input instead of crashing.Verification
Two new tests were added:
test_empty_param_value_no_crash—attachment; filename=test_empty_param_value_multiple—attachment; name=foo; filename=