From 48b425152a6b0ba81db0da546e97aee7be992c57 Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Thu, 23 Jul 2020 07:00:05 -0700 Subject: [PATCH] cover compression table too big branch --- tests/test_name.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_name.py b/tests/test_name.py index 0d3f968b..2ad1e833 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) -- 2.47.3