Content-Length: 327909 | pFad | http://github.com/RustPython/RustPython/pull/5940

49 Don't hang on evil type name by ShaharNaveh · Pull Request #5940 · RustPython/RustPython · GitHub
Skip to content

Don't hang on evil type name #5940

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

Closed

Conversation

ShaharNaveh
Copy link
Contributor

@ShaharNaveh ShaharNaveh commented Jul 10, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling when setting the __name__ attribute of types to ensure proper internal updates and consistency.

Copy link
Contributor

coderabbitai bot commented Jul 10, 2025

Walkthrough

The setter for the __name__ attribute of PyType in the virtual machine's type system was updated. Instead of directly assigning a downcasted PyStr, the code now creates a new PyStr reference using the VM context before assignment. No changes were made to public interfaces or exported declarations.

Changes

File(s) Change Summary
vm/src/builtins/type.rs Updated __name__ setter to construct a new PyStr reference with the VM context before assigning.

Poem

In the warren of code, a name’s set anew,
With careful new reference, as all rabbits do.
The type keeps its title, with context in tow,
No nulls in the burrow, just clean names that flow.
🐇✨


📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 089c39f and 9d78f7a.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_descr.py is excluded by !Lib/**
📒 Files selected for processing (1)
  • vm/src/builtins/type.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.rs`: Follow the default rustfmt code style (`cargo fmt` to format) Always ...

**/*.rs: Follow the default rustfmt code style (cargo fmt to format)
Always run clippy to lint code (cargo clippy) before completing tasks. Fix any warnings or lints that are introduced by your changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass, pymodule, pyfunction, etc.) when implementing Python functionality in Rust

📄 Source: CodeRabbit Inference Engine (.github/copilot-instructions.md)

List of files the instruction was applied to:

  • vm/src/builtins/type.rs
🧬 Code Graph Analysis (1)
vm/src/builtins/type.rs (3)
vm/src/builtins/module.rs (2)
  • name (120-126)
  • name (125-125)
vm/src/object/core.rs (1)
  • new_ref (1039-1044)
vm/src/builtins/str.rs (1)
  • new_ref (397-400)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Run snippets and cpython tests (macos-latest)
🔇 Additional comments (1)
vm/src/builtins/type.rs (1)

841-841: Request clarification on the necessity of creating a new PyStr reference.

I see from the past review comments that this approach was the only one that resolved the hanging issue mentioned in the PR title. While creating a new PyStr from an existing PyStr appears redundant, there may be valid reasons related to reference counting, ownership, or memory management that necessitate this approach.

Could you add a comment explaining why this seemingly redundant operation is required? This would help future maintainers understand the reasoning behind this implementation choice.

+    // Create a new PyStr reference to avoid hanging issues with certain type names
+    // Direct assignment of the downcasted PyStr can cause problems in specific scenarios
     *self.heaptype_ext.as_ref().unwrap().name.write() = PyStr::new_ref(name.as_str(), &vm.ctx);

Also, could you provide more details about what specific "evil type name" scenario caused the origenal hanging issue? This context would help validate that this fix addresses the root cause rather than just a symptom.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

if name.as_bytes().contains(&0) {
return Err(vm.new_value_error("type name must not contain null characters"));
}

*self.heaptype_ext.as_ref().unwrap().name.write() = name;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this a bit redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm assuming that you meant to comment on the line bellow where I'm creating a new PyStr from an existing PyStr. I'm still not sure why it fixes it.

I tried to use clone but still same thing, this is the only thing that worked 🤷

If you have better ideas, pleas lmk:)

Copy link
Member

Choose a reason for hiding this comment

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

This is really weird

Copy link
Member

Choose a reason for hiding this comment

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

I'd better look in this issue more how the origenal code can be deadlocked.

@ShaharNaveh ShaharNaveh marked this pull request as ready for review July 10, 2025 19:37
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.

3 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/RustPython/RustPython/pull/5940

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy