Annotation of pkgsrc/lang/python27/patches/patch-Lib_test_multibytecodec__support.py, revision 1.1.2.2

1.1.2.2 ! tm          1: $NetBSD: patch-Lib_test_multibytecodec__support.py,v 1.1 2021/10/10 03:00:59 gutteridge Exp $
        !             2: 
        !             3: Fix CVE-2020-27619: No longer call eval() on content received via HTTP in the CJK codec tests
        !             4: Via Fedora:
        !             5: https://src.fedoraproject.org/rpms/python2.7/blob/rawhide/f/00355-CVE-2020-27619.patch
        !             6: 
        !             7: --- Lib/test/multibytecodec_support.py.orig    2020-04-19 21:13:39.000000000 +0000
        !             8: +++ Lib/test/multibytecodec_support.py
        !             9: @@ -279,30 +279,22 @@ class TestBase_Mapping(unittest.TestCase
        !            10:              self._test_mapping_file_plain()
        !            11:  
        !            12:      def _test_mapping_file_plain(self):
        !            13: -        _unichr = lambda c: eval("u'\\U%08x'" % int(c, 16))
        !            14: -        unichrs = lambda s: u''.join(_unichr(c) for c in s.split('+'))
        !            15: +        def unichrs(s):
        !            16: +            return ''.join(unichr(int(x, 16)) for x in s.split('+'))
        !            17:          urt_wa = {}
        !            18:  
        !            19:          with self.open_mapping_file() as f:
        !            20:              for line in f:
        !            21:                  if not line:
        !            22:                      break
        !            23: -                data = line.split('#')[0].strip().split()
        !            24: +                data = line.split('#')[0].split()
        !            25:                  if len(data) != 2:
        !            26:                      continue
        !            27:  
        !            28: -                csetval = eval(data[0])
        !            29: -                if csetval <= 0x7F:
        !            30: -                    csetch = chr(csetval & 0xff)
        !            31: -                elif csetval >= 0x1000000:
        !            32: -                    csetch = chr(csetval >> 24) + chr((csetval >> 16) & 0xff) + \
        !            33: -                             chr((csetval >> 8) & 0xff) + chr(csetval & 0xff)
        !            34: -                elif csetval >= 0x10000:
        !            35: -                    csetch = chr(csetval >> 16) + \
        !            36: -                             chr((csetval >> 8) & 0xff) + chr(csetval & 0xff)
        !            37: -                elif csetval >= 0x100:
        !            38: -                    csetch = chr(csetval >> 8) + chr(csetval & 0xff)
        !            39: -                else:
        !            40: +                if data[0][:2] != '0x':
        !            41: +                    self.fail("Invalid line: {!r}".format(line))
        !            42: +                csetch = bytes.fromhex(data[0][2:])
        !            43: +                if len(csetch) == 1 and 0x80 <= csetch[0]:
        !            44:                      continue
        !            45:  
        !            46:                  unich = unichrs(data[1])

CVSweb <webmaster@jp.NetBSD.org>