| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -262,16 +262,63 @@ def test_loads_reject_unicode_strings(self): | |||
| 262 | 262 | unicode_string = 'T' | |
| 263 | 263 | self.assertRaises(TypeError, marshal.loads, unicode_string) | |
| 264 | 264 | ||
| 265 | + LARGE_SIZE = 2**31 | ||
| 266 | + character_size = 4 if sys.maxunicode > 0xFFFF else 2 | ||
| 267 | + pointer_size = 8 if sys.maxsize > 0xFFFFFFFF else 4 | ||
| 268 | + | ||
| 269 | + class NullWriter: | ||
| 270 | + def write(self, s): | ||
| 271 | + pass | ||
| 272 | + | ||
| 273 | + @unittest.skipIf(LARGE_SIZE > sys.maxsize, "test cannot run on 32-bit systems") | ||
| 274 | + class LargeValuesTestCase(unittest.TestCase): | ||
| 275 | + def check_unmarshallable(self, data): | ||
| 276 | + self.assertRaises(ValueError, marshal.dump, data, NullWriter()) | ||
| 277 | + | ||
| 278 | + @support.bigmemtest(size=LARGE_SIZE, memuse=1, dry_run=False) | ||
| 279 | + def test_bytes(self, size): | ||
| 280 | + self.check_unmarshallable(b'x' * size) | ||
| 281 | + | ||
| 282 | + @support.bigmemtest(size=LARGE_SIZE, memuse=character_size, dry_run=False) | ||
| 283 | + def test_str(self, size): | ||
| 284 | + self.check_unmarshallable('x' * size) | ||
| 285 | + | ||
| 286 | + @support.bigmemtest(size=LARGE_SIZE, memuse=pointer_size, dry_run=False) | ||
| 287 | + def test_tuple(self, size): | ||
| 288 | + self.check_unmarshallable((None,) * size) | ||
| 289 | + | ||
| 290 | + @support.bigmemtest(size=LARGE_SIZE, memuse=pointer_size, dry_run=False) | ||
| 291 | + def test_list(self, size): | ||
| 292 | + self.check_unmarshallable([None] * size) | ||
| 293 | + | ||
| 294 | + @support.bigmemtest(size=LARGE_SIZE, | ||
| 295 | + memuse=pointer_size*12 + sys.getsizeof(LARGE_SIZE-1), | ||
| 296 | + dry_run=False) | ||
| 297 | + def test_set(self, size): | ||
| 298 | + self.check_unmarshallable(set(range(size))) | ||
| 299 | + | ||
| 300 | + @support.bigmemtest(size=LARGE_SIZE, | ||
| 301 | + memuse=pointer_size*12 + sys.getsizeof(LARGE_SIZE-1), | ||
| 302 | + dry_run=False) | ||
| 303 | + def test_frozenset(self, size): | ||
| 304 | + self.check_unmarshallable(frozenset(range(size))) | ||
| 305 | + | ||
| 306 | + @support.bigmemtest(size=LARGE_SIZE, memuse=1, dry_run=False) | ||
| 307 | + def test_bytearray(self, size): | ||
| 308 | + self.check_unmarshallable(bytearray(size)) | ||
| 309 | + | ||
| 265 | 310 | ||
| 266 | 311 | def test_main(): | |
| 267 | 312 | support.run_unittest(IntTestCase, | |
| 268 | - FloatTestCase, | ||
| 269 | - StringTestCase, | ||
| 270 | - CodeTestCase, | ||
| 271 | - ContainerTestCase, | ||
| 272 | - ExceptionTestCase, | ||
| 273 | - BufferTestCase, | ||
| 274 | - BugsTestCase) | ||
| 313 | + FloatTestCase, | ||
| 314 | + StringTestCase, | ||
| 315 | + CodeTestCase, | ||
| 316 | + ContainerTestCase, | ||
| 317 | + ExceptionTestCase, | ||
| 318 | + BufferTestCase, | ||
| 319 | + BugsTestCase, | ||
| 320 | + LargeValuesTestCase, | ||
| 321 | + ) | ||
| 275 | 322 | ||
| 276 | 323 | if __name__ == "__main__": | |
| 277 | 324 | test_main() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,9 @@ What's New in Python 3.2.4 | |||
| 10 | 10 | Core and Builtins | |
| 11 | 11 | ----------------- | |
| 12 | 12 | ||
| 13 | + - Issue #5308: Raise ValueError when marshalling too large object (a sequence | ||
| 14 | + with size >= 2**31), instead of producing illegal marshal data. | ||
| 15 | + | ||
| 13 | 16 | - Issue #12983: Bytes literals with invalid \x escape now raise a SyntaxError | |
| 14 | 17 | and a full traceback including line number. | |
| 15 | 18 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments