GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [3.8] gh-98517: Fix buffer overflows in _sha3 module (GH-98519) (#98527) · python/cpython@948c679

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Lib/test
    • test_hashlib.py
  • Misc/NEWS.d/next/Security
    • 2022-10-21-13-31-47.gh-issue-98517.SXXGfV.rst
  • Modules/_sha3/kcp
    • KeccakSponge.inc
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Lib/test/test_hashlib.py‎

Copy file name to clipboardExpand all lines: Lib/test/test_hashlib.py
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,15 @@ def test_case_md5_huge(self, size):
434434
def test_case_md5_uintmax(self, size):
435435
self.check('md5', b'A'*size, '28138d306ff1b8281f1a9067e1a1a2b3')
436436

437+
@unittest.skipIf(sys.maxsize < _4G - 1, 'test cannot run on 32-bit systems')
438+
@bigmemtest(size=_4G - 1, memuse=1, dry_run=False)
439+
def test_sha3_update_overflow(self, size):
440+
"""Regression test for gh-98517 CVE-2022-37454."""
441+
h = hashlib.sha3_224()
442+
h.update(b'\x01')
443+
h.update(b'\x01'*0xffff_ffff)
444+
self.assertEqual(h.hexdigest(), '80762e8ce6700f114fec0f621fd97c4b9c00147fa052215294cceeed')
445+
437446
# use the three examples from Federal Information Processing Standards
438447
# Publication 180-1, Secure Hash Standard, 1995 April 17
439448
# http://www.itl.nist.gov/div897/pubs/fip180-1.htm
Collapse file

‎Misc/NEWS.d/next/Security/2022-10-21-13-31-47.gh-issue-98517.SXXGfV.rst‎

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Port XKCP's fix for the buffer overflows in SHA-3 (CVE-2022-37454).
Collapse file

‎Modules/_sha3/kcp/KeccakSponge.inc‎

Copy file name to clipboardExpand all lines: Modules/_sha3/kcp/KeccakSponge.inc
+8-7Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ int SpongeAbsorb(SpongeInstance *instance, const unsigned char *data, size_t dat
171171
i = 0;
172172
curData = data;
173173
while(i < dataByteLen) {
174-
if ((instance->byteIOIndex == 0) && (dataByteLen >= (i + rateInBytes))) {
174+
if ((instance->byteIOIndex == 0) && (dataByteLen-i >= rateInBytes)) {
175175
#ifdef SnP_FastLoop_Absorb
176176
/* processing full blocks first */
177177

@@ -199,10 +199,10 @@ int SpongeAbsorb(SpongeInstance *instance, const unsigned char *data, size_t dat
199199
}
200200
else {
201201
/* normal lane: using the message queue */
202-
203-
partialBlock = (unsigned int)(dataByteLen - i);
204-
if (partialBlock+instance->byteIOIndex > rateInBytes)
202+
if (dataByteLen-i > rateInBytes-instance->byteIOIndex)
205203
partialBlock = rateInBytes-instance->byteIOIndex;
204+
else
205+
partialBlock = (unsigned int)(dataByteLen - i);
206206
#ifdef KeccakReference
207207
displayBytes(1, "Block to be absorbed (part)", curData, partialBlock);
208208
#endif
@@ -281,7 +281,7 @@ int SpongeSqueeze(SpongeInstance *instance, unsigned char *data, size_t dataByte
281281
i = 0;
282282
curData = data;
283283
while(i < dataByteLen) {
284-
if ((instance->byteIOIndex == rateInBytes) && (dataByteLen >= (i + rateInBytes))) {
284+
if ((instance->byteIOIndex == rateInBytes) && (dataByteLen-i >= rateInBytes)) {
285285
for(j=dataByteLen-i; j>=rateInBytes; j-=rateInBytes) {
286286
SnP_Permute(instance->state);
287287
SnP_ExtractBytes(instance->state, curData, 0, rateInBytes);
@@ -299,9 +299,10 @@ int SpongeSqueeze(SpongeInstance *instance, unsigned char *data, size_t dataByte
299299
SnP_Permute(instance->state);
300300
instance->byteIOIndex = 0;
301301
}
302-
partialBlock = (unsigned int)(dataByteLen - i);
303-
if (partialBlock+instance->byteIOIndex > rateInBytes)
302+
if (dataByteLen-i > rateInBytes-instance->byteIOIndex)
304303
partialBlock = rateInBytes-instance->byteIOIndex;
304+
else
305+
partialBlock = (unsigned int)(dataByteLen - i);
305306
i += partialBlock;
306307

307308
SnP_ExtractBytes(instance->state, curData, instance->byteIOIndex, partialBlock);

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.