Skip to content

Conversation

@shin-
Copy link
Contributor

@shin- shin- commented Jan 29, 2018

This PR changes the behavior of tarfile.itn to cast the input argument n to an integer for bitwise operations.

https://bugs.python.org/issue32713

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

Thanks again to your contribution and we look forward to looking at it!

Lib/tarfile.py Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't be better to convert n to int at the begin of the function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My concern in doing so was that the loss of precision might lead to unwanted results if it is done before the comparisons (e.g. -0.1 becomes 0). That said, it may not matter in any practical case.

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 a good example why this should be done before the comparisons. With this patch itn() produces incorrect results for values between -1 and 0.

>>> tarfile.itn(-0.1)
bytearray(b'\xff\x00\x00\x00\x00\x00\x00\x00')
>>> tarfile.nti(tarfile.itn(-0.1))
-72057594037927936

Please add this case to tests.

Lib/tarfile.py Outdated
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 a good example why this should be done before the comparisons. With this patch itn() produces incorrect results for values between -1 and 0.

>>> tarfile.itn(-0.1)
bytearray(b'\xff\x00\x00\x00\x00\x00\x00\x00')
>>> tarfile.nti(tarfile.itn(-0.1))
-72057594037927936

Please add this case to tests.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@shin-
Copy link
Contributor Author

shin- commented Feb 26, 2018

Thank you for the review!

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@serhiy-storchaka: please review the changes made to this pull request.

Copy link
Member

Choose a reason for hiding this comment

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

Please add a period at the end of the sentence and "Patch by yourname."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done 👍

@serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error needs backport to 3.6 labels Feb 26, 2018
@serhiy-storchaka serhiy-storchaka merged commit 72d9b2b into python:master Feb 27, 2018
@miss-islington
Copy link
Contributor

Thanks @shin- for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.6, 3.7.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 27, 2018
@bedevere-bot
Copy link

GH-5917 is a backport of this pull request to the 3.7 branch.

@miss-islington
Copy link
Contributor

Sorry, @shin- and @serhiy-storchaka, I could not cleanly backport this to 2.7 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 72d9b2be36f091793ae7ffc5ad751f040c6e6ad3 2.7

@bedevere-bot
Copy link

GH-5918 is a backport of this pull request to the 3.6 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 27, 2018
miss-islington added a commit that referenced this pull request Feb 27, 2018
miss-islington added a commit that referenced this pull request Feb 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants