Skip to content
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

hash() on strings containing only null characters returns the length of the strings #57919

Closed
RamchandraApte mannequin opened this issue Jan 4, 2012 · 3 comments
Closed
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@RamchandraApte
Copy link
Mannequin

RamchandraApte mannequin commented Jan 4, 2012

BPO 13710
Nosy @jcea, @benjaminp

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2012-01-04.05:05:24.660>
created_at = <Date 2012-01-04.04:58:50.246>
labels = ['interpreter-core', 'type-bug']
title = 'hash() on strings containing only null characters returns the length of the strings'
updated_at = <Date 2012-01-04.05:14:51.232>
user = 'https://bugs.python.org/RamchandraApte'

bugs.python.org fields:

activity = <Date 2012-01-04.05:14:51.232>
actor = 'jcea'
assignee = 'none'
closed = True
closed_date = <Date 2012-01-04.05:05:24.660>
closer = 'benjamin.peterson'
components = ['Interpreter Core']
creation = <Date 2012-01-04.04:58:50.246>
creator = 'Ramchandra Apte'
dependencies = []
files = []
hgrepos = []
issue_num = 13710
keywords = []
message_count = 3.0
messages = ['150587', '150588', '150590']
nosy_count = 3.0
nosy_names = ['jcea', 'benjamin.peterson', 'Ramchandra Apte']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue13710'
versions = ['Python 3.2', 'Python 3.3']

@RamchandraApte
Copy link
Mannequin Author

RamchandraApte mannequin commented Jan 4, 2012

If you run hash on strings containing only null characters it returns the length of the string
>>> hash("\0")
1
>>> hash("\0\0")
2
>>> hash("\0"*1000)
1000
This behaviour is not like proper hash functions.
The hashes of these strings should exhibit the avalanche effect like in a proper hash function.

@RamchandraApte RamchandraApte mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Jan 4, 2012
@RamchandraApte RamchandraApte mannequin changed the title hash() on string containing only null characters returns the length of the string hash() on string containing only null characters returns the length of the strings Jan 4, 2012
@RamchandraApte RamchandraApte mannequin changed the title hash() on string containing only null characters returns the length of the strings hash() on strings containing only null characters returns the length of the strings Jan 4, 2012
@benjaminp
Copy link
Contributor

No. Python's dictionary implementation is designed to handle hash functions with the properties of Python's.

@jcea
Copy link
Member

jcea commented Jan 4, 2012

Object hashes are not crypto hashes. Use hashlib module for crypto.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants