Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
03a9d2a2
Commit
03a9d2a2
authored
Sep 10, 2012
by
Jesus Cea
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Closes #15908: SHA1 crashes in 64 bits when the string to hash is bigger than 2**32 bytes
parent
dc0170a8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
3 deletions
+27
-3
Lib/test/test_hashlib.py
Lib/test/test_hashlib.py
+8
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/shamodule.c
Modules/shamodule.c
+16
-3
No files found.
Lib/test/test_hashlib.py
View file @
03a9d2a2
...
...
@@ -228,6 +228,14 @@ class HashLibTestCase(unittest.TestCase):
self
.
check
(
'sha1'
,
"a"
*
1000000
,
"34aa973cd4c4daa4f61eeb2bdbad27316534016f"
)
@
precisionbigmemtest
(
size
=
_4G
+
5
,
memuse
=
1
)
def
test_case_sha1_huge
(
self
,
size
):
if
size
==
_4G
+
5
:
try
:
self
.
check
(
'sha1'
,
'A'
*
size
,
'87d745c50e6b2879ffa0fb2c930e9fbfe0dc9a5b'
)
except
OverflowError
:
pass
# 32-bit arch
# use the examples from Federal Information Processing Standards
# Publication 180-2, Secure Hash Standard, 2002 August 1
...
...
Misc/NEWS
View file @
03a9d2a2
...
...
@@ -244,6 +244,9 @@ Library
- Issue #14888: Fix misbehaviour of the _md5 module when called on data
larger than 2**32 bytes.
- Issue #15908: Fix misbehaviour of the sha1 module when called on data
larger than 2**32 bytes.
- Issue #14875: Use float('
inf
') instead of float('
1e66666
') in the json module.
- Issue #14572: Prevent build failures with pre-3.5.0 versions of
...
...
Modules/shamodule.c
View file @
03a9d2a2
...
...
@@ -536,6 +536,8 @@ SHA_new(PyObject *self, PyObject *args, PyObject *kwdict)
static
char
*
kwlist
[]
=
{
"string"
,
NULL
};
SHAobject
*
new
;
Py_buffer
view
=
{
0
};
Py_ssize_t
n
;
unsigned
char
*
buf
;
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwdict
,
"|s*:new"
,
kwlist
,
&
view
))
{
...
...
@@ -554,10 +556,21 @@ SHA_new(PyObject *self, PyObject *args, PyObject *kwdict)
PyBuffer_Release
(
&
view
);
return
NULL
;
}
if
(
view
.
len
>
0
)
{
sha_update
(
new
,
(
unsigned
char
*
)
view
.
buf
,
Py_SAFE_DOWNCAST
(
view
.
len
,
Py_ssize_t
,
unsigned
int
));
n
=
view
.
len
;
buf
=
(
unsigned
char
*
)
view
.
buf
;
while
(
n
>
0
)
{
Py_ssize_t
nbytes
;
if
(
n
>
INT_MAX
)
nbytes
=
INT_MAX
;
else
nbytes
=
n
;
sha_update
(
new
,
buf
,
Py_SAFE_DOWNCAST
(
nbytes
,
Py_ssize_t
,
unsigned
int
));
buf
+=
nbytes
;
n
-=
nbytes
;
}
PyBuffer_Release
(
&
view
);
return
(
PyObject
*
)
new
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment