]> granicus.if.org Git - python/commitdiff
Issue #29444: Fixed out-of-bounds buffer access in the group() method of
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 4 Feb 2017 20:55:40 +0000 (22:55 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 4 Feb 2017 20:55:40 +0000 (22:55 +0200)
the match object.  Based on patch by WGH.

1  2 
Lib/test/test_re.py
Misc/NEWS
Modules/_sre.c

index 4bdaa4b6c627097ec07e56f7acb5157c5c57a7e0,9acd5abbfd77763838315cdc2f536fd65b13b616..b945cf094e99c17df81835e9f03196ada32b569d
@@@ -1772,58 -1679,16 +1772,68 @@@ SUBPATTERN None 0 
          self.checkPatternError(r'(?<>)', 'unknown extension ?<>', 1)
          self.checkPatternError(r'(?', 'unexpected end of pattern', 2)
  
 +    def test_enum(self):
 +        # Issue #28082: Check that str(flag) returns a human readable string
 +        # instead of an integer
 +        self.assertIn('ASCII', str(re.A))
 +        self.assertIn('DOTALL', str(re.S))
 +
 +    def test_pattern_compare(self):
 +        pattern1 = re.compile('abc', re.IGNORECASE)
 +
 +        # equal to itself
 +        self.assertEqual(pattern1, pattern1)
 +        self.assertFalse(pattern1 != pattern1)
 +
 +        # equal
 +        re.purge()
 +        pattern2 = re.compile('abc', re.IGNORECASE)
 +        self.assertEqual(hash(pattern2), hash(pattern1))
 +        self.assertEqual(pattern2, pattern1)
 +
 +        # not equal: different pattern
 +        re.purge()
 +        pattern3 = re.compile('XYZ', re.IGNORECASE)
 +        # Don't test hash(pattern3) != hash(pattern1) because there is no
 +        # warranty that hash values are different
 +        self.assertNotEqual(pattern3, pattern1)
 +
 +        # not equal: different flag (flags=0)
 +        re.purge()
 +        pattern4 = re.compile('abc')
 +        self.assertNotEqual(pattern4, pattern1)
 +
 +        # only == and != comparison operators are supported
 +        with self.assertRaises(TypeError):
 +            pattern1 < pattern2
 +
 +    def test_pattern_compare_bytes(self):
 +        pattern1 = re.compile(b'abc')
 +
 +        # equal: test bytes patterns
 +        re.purge()
 +        pattern2 = re.compile(b'abc')
 +        self.assertEqual(hash(pattern2), hash(pattern1))
 +        self.assertEqual(pattern2, pattern1)
 +
 +        # not equal: pattern of a different types (str vs bytes),
 +        # comparison must not raise a BytesWarning
 +        re.purge()
 +        pattern3 = re.compile('abc')
 +        with warnings.catch_warnings():
 +            warnings.simplefilter('error', BytesWarning)
 +            self.assertNotEqual(pattern3, pattern1)
 +
+     def test_bug_29444(self):
+         s = bytearray(b'abcdefgh')
+         m = re.search(b'[a-h]+', s)
+         m2 = re.search(b'[e-h]+', s)
+         self.assertEqual(m.group(), b'abcdefgh')
+         self.assertEqual(m2.group(), b'efgh')
+         s[:] = b'xyz'
+         self.assertEqual(m.group(), b'xyz')
+         self.assertEqual(m2.group(), b'')
  
  class PatternReprTests(unittest.TestCase):
      def check(self, pattern, expected):
diff --cc Misc/NEWS
Simple merge
diff --cc Modules/_sre.c
Simple merge