Issues #23363, #23364, #23365, #23366: Fixed itertools overflow tests.
Used PyMem_New to check overflow.
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
index 3c7dd49..bde7ab6 100644
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -139,7 +139,7 @@
 
     @test_support.bigaddrspacetest
     def test_combinations_overflow(self):
-        with self.assertRaises(OverflowError):
+        with self.assertRaises((OverflowError, MemoryError)):
             combinations("AA", 2**29)
 
     @test_support.impl_detail("tuple reuse is specific to CPython")
@@ -215,7 +215,7 @@
 
     @test_support.bigaddrspacetest
     def test_combinations_with_replacement_overflow(self):
-        with self.assertRaises(OverflowError):
+        with self.assertRaises((OverflowError, MemoryError)):
             combinations_with_replacement("AA", 2**30)
 
     @test_support.impl_detail("tuple reuse is specific to CPython")
@@ -286,10 +286,8 @@
 
     @test_support.bigaddrspacetest
     def test_permutations_overflow(self):
-        with self.assertRaises(OverflowError):
+        with self.assertRaises((OverflowError, MemoryError)):
             permutations("A", 2**30)
-        with self.assertRaises(OverflowError):
-            permutations("A", 2, 2**30)
 
     @test_support.impl_detail("tuple reuse is specific to CPython")
     def test_permutations_tuple_reuse(self):
@@ -711,8 +709,8 @@
 
     @test_support.bigaddrspacetest
     def test_product_overflow(self):
-        with self.assertRaises(OverflowError):
-            product(["a"]*(2**16), repeat=2**16)
+        with self.assertRaises((OverflowError, MemoryError)):
+            product(*(['ab']*2**5), repeat=2**25)
 
     @test_support.impl_detail("tuple reuse is specific to CPython")
     def test_product_tuple_reuse(self):