Fix get_ranges crash when content_length is None#2077
Open
bysiber wants to merge 1 commit intocherrypy:mainfrom
Open
Fix get_ranges crash when content_length is None#2077bysiber wants to merge 1 commit intocherrypy:mainfrom
bysiber wants to merge 1 commit intocherrypy:mainfrom
Conversation
When serving resources via serve_fileobj (e.g. zipapp resources), content_length can be None. This caused get_ranges() to crash with TypeError when comparing integers against None. Return None early when content_length is None, consistent with how the function already handles missing Range headers. Added regression tests for this case.
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.
When serving resources via
serve_fileobj(e.g. zipapp resources loaded withimportlib.resources),content_lengthcan beNone. This causesget_ranges()to crash with aTypeErrorwhen comparing integers againstNone.This adds an early return of
Nonewhencontent_length is None, which is consistent with how the function already handles missing Range headers.Includes regression tests for this case.
What kind of change does this PR introduce?
What is the related issue number (starting with
#)Fixes #2024
What is the current behavior? (You can also link to an open issue here)
get_ranges()raisesTypeError: '>=' not supported between instances of 'int' and 'NoneType'whencontent_lengthisNone.What is the new behavior (if this is a feature change)?
get_ranges()returnsNonewhencontent_lengthisNone, avoiding the crash.Checklist:
and description in grammatically correct, complete sentences