8000 Handle MemoryError for list and strings. by philippeitis · Pull Request #1779 · RustPython/RustPython · GitHub
[go: up one dir, main page]

Skip to content

Handle MemoryError for list and strings. #1779

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

philippeitis
Copy link
Contributor
@philippeitis philippeitis commented Feb 27, 2020

This aims to address #1750 by raising a Memory error for excessively large allocations. It adds a MAX_MEMORY_SIZE const to VM which is then used by objlist.rs and objstr.rs when doing imul or mul operations.

@coolreader18
Copy link
Member

I'm not sure if this is the correct approach; 2**61 bytes is 2.3 exabytes, which probably wouldn't get hit before an actual OOM error occurs in the process. There is a RFC that allows for catching OOMs in a few different ways (try_reserve -> Result<(), ...> functions on Vec or String, oom=panic rustc option that will panic and unwind instead of just aborting) but none of them are stable yet. I'm not sure how to approach this problem, honestly.

@philippeitis
Copy link
Contributor Author

That is true, but this is also a reasonable sanity check, since a list with 8 byte pointers can only contain up to usize::MAX / 8 elements. Beyond that, allocating becomes the virtual machine's problem and will need to dealt with accordingly.

Copy link
@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

it would be great if you could rebase it for further review.

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
0