Thanks to visit codestin.com
Credit goes to github.com

Skip to content

GH-107450: fix unexpected OverflowError in testMemoryErrorBigSource #110801

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
wants to merge 1 commit into from

Conversation

FFY00
Copy link
Member

@FFY00 FFY00 commented Oct 13, 2023

@AlexWaygood
Copy link
Member

FYI @lysnikolaou already opened #110768 to fix this :)

@lysnikolaou
Copy link
Member

I like this better than my test. @FFY00 Can you add the changes that #110768 adds, i.e. @support.requires_resource, @support.bigmemtest and not checking the error message?

@AlexWaygood AlexWaygood changed the title GH-110800: fix unexpected OverflowError in testMemoryErrorBigSource GH-107450: fix unexpected OverflowError in testMemoryErrorBigSource Oct 13, 2023
@FFY00
Copy link
Member Author

FFY00 commented Oct 13, 2023

Done, and sorry for not noticing the already open issue 😅

@lysnikolaou
Copy link
Member

lysnikolaou commented Oct 13, 2023

@FFY00 #110768 was merged. Would you still like to improve the test there or should we close this?

@FFY00
Copy link
Member Author

FFY00 commented Oct 13, 2023

Since I can just rebase or merge main easily, we can still add the improvements.

@FFY00
Copy link
Member Author

FFY00 commented Oct 13, 2023

Ugh, the merge shows the extra changes from main on the Github UI. Next time I'll just rebase and force-push, which should be less confusing 🙃

Copy link
Member

@lysnikolaou lysnikolaou left a comment

Choose a reason for hiding this comment

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

A couple of comments. Could you maybe merge upstream/main here so that the diff is okay?

# the padding length needs to be more than INT_MAX, but we can't
# multiple a sequence by a number that doesn't fit Py_ssize_t,
# otherwise we will get an OverflowError (see PySequence_Repeat)
padding = ' ' * ((ctypes.sizeof(ctypes.c_int) + 1) / 8)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this tests the correct thing. The buffer is way too small to overflow, probably a typo?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, I forgot it returns the number of bytes 😅

Comment on lines 322 to 323
@unittest.skipIf(ctypes.sizeof(ctypes.c_ssize_t) > ctypes.sizeof(ctypes.c_int),
"Py_ssize_t is bigger than INT_MAX, so this is unreachable")
Copy link
Member

Choose a reason for hiding this comment

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

This should probably the other way around. If sizeof(ssize_t) <= sizeof(int) the cast is always safe, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah 🙃

@unittest.skipIf(ctypes.sizeof(ctypes.c_ssize_t) > ctypes.sizeof(ctypes.c_int),
"Py_ssize_t is bigger than INT_MAX, so this is unreachable")
@unittest.skipIf(ctypes.sizeof(ctypes.c_int) >= ctypes.sizeof(ctypes.c_ssize_t),
"INT_MAX is bigger than Py_ssize_t, so this is unreachable")
@support.requires_resource('cpu')
@support.bigmemtest(support._2G, memuse=1.5)
def testMemoryErrorBigSource(self):
Copy link
Member

Choose a reason for hiding this comment

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

This probably needs another merge, since a _size argument has been added. Also, it might be good to request the size of the buffer we want and then use that. Something like:

@support.bigmemtest(2 ** (ctypes.sizeof(ctypes.c_int) * 8), memuse=1)
    def testMemoryErrorBigSource(self, size):
        padding = '        ' * (size // 8)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@FFY00
Copy link
Member Author

FFY00 commented Oct 13, 2023

@lysnikolaou is everything addressed, or is there still anything missing?

@pablogsal
Copy link
Member

There is something wrong with the commits in this PR because there are plenty of unrelated changes

…urce

Signed-off-by: Filipe Laíns <[email protected]>

add the suggested test markers

Signed-off-by: Filipe Laíns <[email protected]>

fix incorrect logic

Signed-off-by: Filipe Laíns <[email protected]>

add _size arg that got lost in the merge

Signed-off-by: Filipe Laíns <[email protected]>
@FFY00
Copy link
Member Author

FFY00 commented Oct 13, 2023

I think it's just the Github UI showing all the changes from the merge commits, instead of showing the difference with main. I will rebase on main and force-push, which should fix it.

@lysnikolaou
Copy link
Member

@FFY00 Thanks for taking time to work on this.

Turns out the fix was a bit more complex than expacted, both for the test (which makes the buildbot fail) and for the underlying issue. I've opened #110832 which fixes both issues, so I'd suggest to close this and have you as a co-author there. Are you okay with that?

1 similar comment
@lysnikolaou
Copy link
Member

@FFY00 Thanks for taking time to work on this.

Turns out the fix was a bit more complex than expacted, both for the test (which makes the buildbot fail) and for the underlying issue. I've opened #110832 which fixes both issues, so I'd suggest to close this and have you as a co-author there. Are you okay with that?

@FFY00
Copy link
Member Author

FFY00 commented Oct 13, 2023

Sounds good 👍

@FFY00 FFY00 closed this Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants