List of commits:
Subject Hash Author Date (UTC)
bpo-10030: Sped up reading encrypted ZIP files by 2 times. (#550) 06e522521c06671b4559eecf9e2a185c2d62c141 Serhiy Storchaka 2017-03-30 16:09:08
bpo-29935: Fixed error messages in the index() method of tuple, list and deque (#887) d4edfc9abffca965e76ebc5957a92031a4d6c4d4 Serhiy Storchaka 2017-03-30 15:29:23
bpo-29204: Emit warnings for already deprecated ElementTree features. (#773) 762ec97ea68a1126b8855996c61fa8239dc9fff7 Serhiy Storchaka 2017-03-30 15:12:06
bpo-29887: Test normalization now fails if download fails (#905) 722a3af092b94983aa26f5e591fb1b45e2c2a0ff Victor Stinner 2017-03-30 15:06:53
bpo-20548: Use specific asserts in warnings and exceptions tests (#788) f15c4d374a07c576c0e8349b16604f6dbad0b953 Serhiy Storchaka 2017-03-30 15:05:08
bpo-29913: deprecate compare_networks() in documentation (GH-865) 16f852345bcdec1bbb15e5363fad6b33bf960912 s-sanjay 2017-03-30 07:44:29
bpo-29918: Add missed "const" modifiers in C API documentation. (#846) 84b8e92e463bd6a5174bd3e5a6543580f6319c57 Serhiy Storchaka 2017-03-30 07:01:03
bpo-27863: Fixed multiple crashes in ElementTree. (#765) 576def096ec7b64814e038f03290031f172886c3 Serhiy Storchaka 2017-03-30 06:47:31
bpo-29816: Shift operation now has less opportunity to raise OverflowError. (#680) 918403cfc3304d27e80fb792357f40bb3ba69c4e Serhiy Storchaka 2017-03-30 06:47:07
bpo-29852: Argument Clinic Py_ssize_t converter now supports None (#716) 762bf40438a572a398e500c74e38f9894ea20a45 Serhiy Storchaka 2017-03-30 06:15:31
bpo-25996: Added support of file descriptors in os.scandir() on Unix. (#502) ea720fe7e99d68924deab38de955fe97f87e2b29 Serhiy Storchaka 2017-03-30 06:12:31
bpo-24821: Fixed the slowing down to 25 times in the searching of some (#505) 0a58f72762353768c7d26412e627ff196aac6c4e Serhiy Storchaka 2017-03-30 06:11:10
bpo-29878: Add global instances of int for 0 and 1. (#852) ba85d69a3e3610bdd05f0dd372cf4ebca178c7fb Serhiy Storchaka 2017-03-30 06:09:41
Remove an unrequired TODO in test_urllib2. (#897) e6911a44f69c0d302db60f49952a9cf69da69a2b Senthil Kumaran 2017-03-30 06:02:29
bpo-29917: DOC: Remove link from PyMethodDef (#890) c3c7ef088583cc12bd218138036d1edb6de9c63f csabella 2017-03-30 00:27:50
bpo-29677: DOC: clarify documentation for `round` (GH-877) 85deefcf61d3cc192846f41a4ccc6df17da60c98 csabella 2017-03-29 21:14:06
bpo-29932: Fix small error message typos in arraymodule.c (GH-888) a90e64b78d74b80a7cbcca2237280c724b99431b Sylvain 2017-03-29 18:09:22
bpo-29927: Remove duplicate BufferError init and unnecessary semicolons (GH-866) c431854a0963d4ec2875efab2d2425a738895280 Louie Lu 2017-03-29 05:28:15
bpo-29936: fix typo __GNU*C*_MINOR__ (#878) 83371f4f7f70406ea5d08c5fa8dbdbbcc0355ee1 Niklas Fiekas 2017-03-29 04:58:01
bpo-28699: fix abnormal behaviour of pools in multiprocessing.pool (GH-693) 794623bdb232eafd8925f76470209afcdcbcdcd2 Xiang Zhang 2017-03-29 03:58:54
Commit 06e522521c06671b4559eecf9e2a185c2d62c141 - bpo-10030: Sped up reading encrypted ZIP files by 2 times. (#550)
Author: Serhiy Storchaka
Author date (UTC): 2017-03-30 16:09
Committer name: GitHub
Committer date (UTC): 2017-03-30 16:09
Parent(s): d4edfc9abffca965e76ebc5957a92031a4d6c4d4
Signer:
Signing key:
Signing status: N
Tree: 62fadf5104aca4268033dd04847ea253e98012fc
File Lines added Lines deleted
Lib/zipfile.py 55 57
Misc/NEWS 2 0
File Lib/zipfile.py changed (mode: 100644) (index 8a19ca246b..6fdf2c398d)
... ... class ZipInfo (object):
509 509 return self.filename[-1] == '/' return self.filename[-1] == '/'
510 510
511 511
512 class _ZipDecrypter:
513 """Class to handle decryption of files stored within a ZIP archive.
512 # ZIP encryption uses the CRC32 one-byte primitive for scrambling some
513 # internal keys. We noticed that a direct implementation is faster than
514 # relying on binascii.crc32().
515
516 _crctable = None
517 def _gen_crc(crc):
518 for j in range(8):
519 if crc & 1:
520 crc = (crc >> 1) ^ 0xEDB88320
521 else:
522 crc >>= 1
523 return crc
524
525 # ZIP supports a password-based form of encryption. Even though known
526 # plaintext attacks have been found against it, it is still useful
527 # to be able to get data out of such a file.
528 #
529 # Usage:
530 # zd = _ZipDecrypter(mypwd)
531 # plain_bytes = zd(cypher_bytes)
532
533 def _ZipDecrypter(pwd):
534 key0 = 305419896
535 key1 = 591751049
536 key2 = 878082192
537
538 global _crctable
539 if _crctable is None:
540 _crctable = list(map(_gen_crc, range(256)))
541 crctable = _crctable
542
543 def crc32(ch, crc):
544 """Compute the CRC32 primitive on one byte."""
545 return (crc >> 8) ^ crctable[(crc ^ ch) & 0xFF]
514 546
515 ZIP supports a password-based form of encryption. Even though known
516 plaintext attacks have been found against it, it is still useful
517 to be able to get data out of such a file.
547 def update_keys(c):
548 nonlocal key0, key1, key2
549 key0 = crc32(c, key0)
550 key1 = (key1 + (key0 & 0xFF)) & 0xFFFFFFFF
551 key1 = (key1 * 134775813 + 1) & 0xFFFFFFFF
552 key2 = crc32(key1 >> 24, key2)
518 553
519 Usage:
520 zd = _ZipDecrypter(mypwd)
521 plain_char = zd(cypher_char)
522 plain_text = map(zd, cypher_text)
523 """
554 for p in pwd:
555 update_keys(p)
524 556
525 def _GenerateCRCTable():
526 """Generate a CRC-32 table.
557 def decrypter(data):
558 """Decrypt a bytes object."""
559 result = bytearray()
560 append = result.append
561 for c in data:
562 k = key2 | 2
563 c ^= ((k * (k^1)) >> 8) & 0xFF
564 update_keys(c)
565 append(c)
566 return bytes(result)
527 567
528 ZIP encryption uses the CRC32 one-byte primitive for scrambling some
529 internal keys. We noticed that a direct implementation is faster than
530 relying on binascii.crc32().
531 """
532 poly = 0xedb88320
533 table = [0] * 256
534 for i in range(256):
535 crc = i
536 for j in range(8):
537 if crc & 1:
538 crc = ((crc >> 1) & 0x7FFFFFFF) ^ poly
539 else:
540 crc = ((crc >> 1) & 0x7FFFFFFF)
541 table[i] = crc
542 return table
543 crctable = None
544
545 def _crc32(self, ch, crc):
546 """Compute the CRC32 primitive on one byte."""
547 return ((crc >> 8) & 0xffffff) ^ self.crctable[(crc ^ ch) & 0xff]
548
549 def __init__(self, pwd):
550 if _ZipDecrypter.crctable is None:
551 _ZipDecrypter.crctable = _ZipDecrypter._GenerateCRCTable()
552 self.key0 = 305419896
553 self.key1 = 591751049
554 self.key2 = 878082192
555 for p in pwd:
556 self._UpdateKeys(p)
557
558 def _UpdateKeys(self, c):
559 self.key0 = self._crc32(c, self.key0)
560 self.key1 = (self.key1 + (self.key0 & 255)) & 4294967295
561 self.key1 = (self.key1 * 134775813 + 1) & 4294967295
562 self.key2 = self._crc32((self.key1 >> 24) & 255, self.key2)
563
564 def __call__(self, c):
565 """Decrypt a single character."""
566 assert isinstance(c, int)
567 k = self.key2 | 2
568 c = c ^ (((k * (k^1)) >> 8) & 255)
569 self._UpdateKeys(c)
570 return c
568 return decrypter
571 569
572 570
573 571 class LZMACompressor: class LZMACompressor:
 
... ... class ZipExtFile(io.BufferedIOBase):
953 951 raise EOFError raise EOFError
954 952
955 953 if self._decrypter is not None: if self._decrypter is not None:
956 data = bytes(map(self._decrypter, data))
954 data = self._decrypter(data)
957 955 return data return data
958 956
959 957 def close(self): def close(self):
 
... ... class ZipFile:
1411 1409 # or the MSB of the file time depending on the header type # or the MSB of the file time depending on the header type
1412 1410 # and is used to check the correctness of the password. # and is used to check the correctness of the password.
1413 1411 header = zef_file.read(12) header = zef_file.read(12)
1414 h = list(map(zd, header[0:12]))
1412 h = zd(header[0:12])
1415 1413 if zinfo.flag_bits & 0x8: if zinfo.flag_bits & 0x8:
1416 1414 # compare against the file type from extended local headers # compare against the file type from extended local headers
1417 1415 check_byte = (zinfo._raw_time >> 8) & 0xff check_byte = (zinfo._raw_time >> 8) & 0xff
File Misc/NEWS changed (mode: 100644) (index 9c434a7735..8646b8ce45)
... ... Extension Modules
301 301 Library Library
302 302 ------- -------
303 303
304 - bpo-10030: Sped up reading encrypted ZIP files by 2 times.
305
304 306 - bpo-29204: Element.getiterator() and the html parameter of XMLParser() were - bpo-29204: Element.getiterator() and the html parameter of XMLParser() were
305 307 deprecated only in the documentation (since Python 3.2 and 3.4 correspondintly). deprecated only in the documentation (since Python 3.2 and 3.4 correspondintly).
306 308 Now using them emits a deprecation warning. Now using them emits a deprecation warning.
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/benf_wspdigital/cpython

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/benf_wspdigital/cpython

Clone this repository using git:
git clone git://git.rocketgit.com/user/benf_wspdigital/cpython

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main