-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
bpo-32503: Avoid creating too small frames in pickles. #5127
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
bpo-32503: Avoid creating too small frames in pickles. #5127
Conversation
| frame_size = self.FRAME_SIZE_TARGET | ||
| num_frames = 20 | ||
| obj = [bytes([i]) * frame_size for i in range(num_frames)] | ||
| obj = {i: bytes([i]) * frame_size for i in range(num_frames)} |
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.
IIUC, small integers don't produce a frame? Can you add a comment?
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.
I may misunderstand, actually...
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.
I have added small objects (dict keys) between large objects.
Lib/test/pickletester.py
Outdated
| # to the pickle's end. | ||
| frame_size = len(pickled) - last_pos - last_frame_opcode_size | ||
| self.assertEqual(frame_size, last_arg) | ||
| self.assertLessEqual(pos, frame_end) |
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.
This is repeated just below.
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.
Good point. I tried to write these tests in different forms and some checks are left duplicated.
Lib/test/pickletester.py
Outdated
| if pos < frame_end: | ||
| self.assertNotIn(op.name, 'FRAME') | ||
| if op.name in frameless_opcodes: | ||
| self.assertLessEqual(len(arg), self.FRAME_SIZE_TARGET) |
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.
Could you add a comment explaining this?
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.
Done.
Lib/test/pickletester.py
Outdated
| self.assertLessEqual(pos, frame_end) | ||
| self.assertLessEqual(pos, frame_end) | ||
| if pos < frame_end: | ||
| self.assertNotIn(op.name, 'FRAME') |
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.
This test looks strange. Perhaps you meant assertNotEqual(op.name, 'FRAME')?
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.
Right.
Lib/test/pickletester.py
Outdated
| self.assertLessEqual(len(arg), self.FRAME_SIZE_TARGET) | ||
| else: | ||
| frame_end = None | ||
| #frameless_start = pos |
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.
Hmm, looks like this should be removed.
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.
Done.
| (op.name in frameless_opcodes and | ||
| len(arg) > self.FRAME_SIZE_TARGET)): | ||
| if frameless_start is not None: | ||
| self.assertLess(pos - frameless_start, |
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.
Perhaps comment on this?
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.
Done.
pitrou
left a comment
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.
Thanks for addressing the comments!
|
Thank you for your review! |
https://bugs.python.org/issue32503