Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 201
Prevent invalid scopes request from crashing debug session#2026
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1109,10 +1109,17 @@ def on_scopes_request(self, py_db, request): | ||
| frame_id = request.arguments.frameId | ||
| variables_reference = frame_id | ||
| scopes = [ | ||
| Scope("Locals", ScopeRequest(int(variables_reference), "locals"), False, presentationHint="locals"), | ||
| Scope("Globals", ScopeRequest(int(variables_reference), "globals"), False), | ||
| ] | ||
| try: | ||
| scopes = [ | ||
| Scope("Locals", ScopeRequest(int(variables_reference), "locals"), False, presentationHint="locals"), | ||
| Scope("Globals", ScopeRequest(int(variables_reference), "globals"), False), | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copilot generated: [verified] | ||
| ] | ||
| except (ValueError, TypeError): | ||
| pydev_log.info("Failed to create scopes for frame id: %s", frame_id) | ||
| scopes = [] | ||
| except Exception: | ||
| pydev_log.exception("Failed to create scopes for frame id: %s", frame_id) | ||
| scopes = [] | ||
| body = ScopesResponseBody(scopes) | ||
| scopes_response = pydevd_base_schema.build_response(request, kwargs={"body": body}) | ||
| return NetCommand(CMD_RETURN, 0, scopes_response, is_json=True) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| def test_on_scopes_request_with_valid_frame_id(): | ||
| from _pydevd_bundle._debug_adapter import pydevd_schema, pydevd_base_schema | ||
| from _pydevd_bundle.pydevd_process_net_command_json import PyDevJsonCommandProcessor | ||
| processor = PyDevJsonCommandProcessor(pydevd_base_schema.from_json) | ||
| request = pydevd_schema.ScopesRequest(pydevd_schema.ScopesArguments(frameId=1)) | ||
| result = processor.on_scopes_request(None, request) | ||
| response = result.as_dict | ||
| assert response["success"] is True | ||
| scopes = response["body"]["scopes"] | ||
| assert len(scopes) == 2 | ||
| assert scopes[0]["name"] == "Locals" | ||
| assert scopes[0]["presentationHint"] == "locals" | ||
| assert scopes[1]["name"] == "Globals" | ||
| def test_on_scopes_request_with_invalid_frame_id(): | ||
| from _pydevd_bundle._debug_adapter import pydevd_schema, pydevd_base_schema | ||
| from _pydevd_bundle.pydevd_process_net_command_json import PyDevJsonCommandProcessor | ||
| processor = PyDevJsonCommandProcessor(pydevd_base_schema.from_json) | ||
| request = pydevd_schema.ScopesRequest( | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copilot generated:
[verified] ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 999999 is a valid int, so it wouldn't exercise what we're preventing here, which would be a non-integer value. ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The specific issue we've seen is that the client can send a scopes request using a DAP id that corresponds to a thread instead of a frame. The DAP to id translation converts that to something like | ||
| pydevd_schema.ScopesArguments(frameId="not_a_number") | ||
| ) | ||
| result = processor.on_scopes_request(None, request) | ||
| response = result.as_dict | ||
| assert response["success"] is True | ||
| assert response["body"]["scopes"] == [] | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot generated:
except Exceptionis too broad. The PR description identifiesValueErrorfromint()as the failure mode — catch(ValueError, TypeError)instead. The current catch will silently swallow any future bug inScope()orScopeRequest()constructors (e.g.,AttributeError,KeyError), making those bugs invisible. All three technical reviewers flagged this independently.[unverified][verified]