diff options
| author | Bob Halley <halley@dnspython.org> | 2020-07-23 07:00:05 -0700 |
|---|---|---|
| committer | Bob Halley <halley@dnspython.org> | 2020-07-23 07:00:05 -0700 |
| commit | 48b425152a6b0ba81db0da546e97aee7be992c57 (patch) | |
| tree | 09ad6f27a39b8b4d2a08e4d4ef0e522191a2287a | |
| parent | 16417623fb9221a978e67b62865a65acdb716d20 (diff) | |
| download | dnspython-48b425152a6b0ba81db0da546e97aee7be992c57.tar.gz | |
cover compression table too big branch
| -rw-r--r-- | tests/test_name.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/test_name.py b/tests/test_name.py index 0d3f968..2ad1e83 100644 --- a/tests/test_name.py +++ b/tests/test_name.py @@ -465,6 +465,30 @@ class NameTestCase(unittest.TestCase): n.to_wire(f, compress) self.assertRaises(dns.name.NeedAbsoluteNameOrOrigin, bad) + def testGiantCompressionTable(self): + # Only the first 16KiB of a message can have compression pointers. + f = BytesIO() + compress = {} # type: Dict[dns.name.Name,int] + # exactly 16 bytes encoded + n = dns.name.from_text('0000000000.com.') + n.to_wire(f, compress) + # There are now two entries in the compression table (for the full + # name, and for the com. suffix. + self.assertEqual(len(compress), 2) + for i in range(1023): + # exactly 16 bytes encoded with compression + n = dns.name.from_text(f'{i:013d}.com') + n.to_wire(f, compress) + # There are now 1025 entries in the compression table with + # the last entry at offset 16368. + self.assertEqual(len(compress), 1025) + self.assertEqual(compress[n], 16368) + # Adding another name should not increase the size of the compression + # table, as the pointer would be at offset 16384, which is too big. + n = dns.name.from_text('toobig.com.') + n.to_wire(f, compress) + self.assertEqual(len(compress), 1025) + def testSplit1(self): n = dns.name.from_text('foo.bar.') (prefix, suffix) = n.split(2) |
