Title: TSIG record does not parse after `Message.toWire(maxLength)` truncates records owned by the key name · Issue #417 · dnsjava/dnsjava · GitHub
Open Graph Title: TSIG record does not parse after `Message.toWire(maxLength)` truncates records owned by the key name · Issue #417 · dnsjava/dnsjava
X Title: TSIG record does not parse after `Message.toWire(maxLength)` truncates records owned by the key name · Issue #417 · dnsjava/dnsjava
Description: When Message.toWire(maxLength) has to drop answer records owned by the TSIG key's name, the TSIG record it writes cannot be parsed back (bad compression), and since the parser skips an unreadable additional section when TC is set, the me...
Open Graph Description: When Message.toWire(maxLength) has to drop answer records owned by the TSIG key's name, the TSIG record it writes cannot be parsed back (bad compression), and since the parser skips an unreadable a...
X Description: When Message.toWire(maxLength) has to drop answer records owned by the TSIG key's name, the TSIG record it writes cannot be parsed back (bad compression), and since the parser skips an unreadab...
Opengraph URL: https://github.com/dnsjava/dnsjava/issues/417
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TSIG record does not parse after `Message.toWire(maxLength)` truncates records owned by the key name","articleBody":"When `Message.toWire(maxLength)` has to drop answer records owned by the TSIG key's name, the TSIG record it writes cannot be parsed back (`bad compression`), and since the parser skips an unreadable additional section when TC is set, the message comes back with ARCOUNT 1 and no TSIG. Dropping the same number of answers owned by another name leaves the TSIG readable. The program below shows the three cases, and parses a copy of each result with TC cleared so the error is visible:\n\n```java\nimport java.io.IOException;\nimport java.net.InetAddress;\nimport org.xbill.DNS.ARecord;\nimport org.xbill.DNS.DClass;\nimport org.xbill.DNS.Flags;\nimport org.xbill.DNS.Message;\nimport org.xbill.DNS.Name;\nimport org.xbill.DNS.Rcode;\nimport org.xbill.DNS.Record;\nimport org.xbill.DNS.Section;\nimport org.xbill.DNS.TSIG;\nimport org.xbill.DNS.Type;\n\npublic class Main {\n public static void main(String[] args) throws IOException {\n Name key = Name.fromString(\"key.example.com.\");\n TSIG tsig = new TSIG(TSIG.HMAC_SHA256, key, new byte[16]);\n int max = 12 + 19 + tsig.recordLength() + 4; // header, question and TSIG fit; no answer does\n\n show(message(key, tsig), 512);\n show(message(key, tsig), max);\n show(message(Name.fromString(\"www.example.com.\"), tsig), max);\n }\n\n static Message message(Name answerOwner, TSIG tsig) throws IOException {\n Message m = new Message(1);\n m.addRecord(Record.newRecord(Name.fromString(\"q.example.com.\"), Type.A, DClass.IN), Section.QUESTION);\n for (int i = 1; i \u003c= 5; i++) {\n m.addRecord(new ARecord(answerOwner, DClass.IN, 3600, InetAddress.getByName(\"192.0.2.\" + i)), Section.ANSWER);\n }\n m.setTSIG(tsig, Rcode.NOERROR, null);\n return m;\n }\n\n static void show(Message m, int max) throws IOException {\n byte[] w = m.toWire(max);\n Message back = new Message(w);\n System.out.println(\"toWire(\" + max + \"): \" + w.length + \" bytes, TC=\" + back.getHeader().getFlag(Flags.TC)\n + \", ARCOUNT=\" + back.getHeader().getCount(Section.ADDITIONAL));\n System.out.println(\" additional section: \" + back.getSection(Section.ADDITIONAL));\n byte[] noTc = w.clone();\n noTc[2] &= ~0x02; // clear TC, so that the parser reports errors in the additional section instead of skipping them\n try {\n new Message(noTc);\n } catch (IOException e) {\n System.out.println(\" with TC cleared: \" + e);\n }\n }\n}\n```\n\nOutput:\n\n```\ntoWire(512): 188 bytes, TC=false, ARCOUNT=1\n additional section: [key.example.com.\t0\tANY\tTSIG\thmac-sha256. 1790002669 300 32 pA5Tz/pZW5pb8hgZR/m/8BxJBJDnVeCgbv3amc6Mf/0= NOERROR 0]\ntoWire(129): 104 bytes, TC=true, ARCOUNT=1\n additional section: []\n with TC cleared: org.xbill.DNS.WireParseException: bad compression\ntoWire(129): 108 bytes, TC=true, ARCOUNT=1\n additional section: [key.example.com.\t0\tANY\tTSIG\thmac-sha256. 1790002669 300 32 lSxqUAHUu0fDv7TjrySF9yZcAHCYXJR3NlcN1C7ogGY= NOERROR 0]\n```\n\nIn the second case the message says ARCOUNT 1, but the TSIG record cannot be read back: parsing it fails with `bad compression`, and with TC set that failure is skipped and the message comes back with no TSIG at all. Truncation by itself is not the trigger: in the third case the same budget drops the same number of answers, and the TSIG parses fine. The difference is only that the dropped answers in the second case are owned by the TSIG key's name. I would expect the truncated message to carry a readable TSIG record in both cases.\n\nTested on dnsjava 3.6.5 and on current master (8bed725c).\n\nBTW, this was found by an automated program that writes property-based tests for various open source projects using [hegel](https://github.com/hegeldev/hegel-java) (but it has been reviewed by hand before reporting). We've also potentially found (but not yet hand validated) 44 other bugs in dnsjava. You can see the tests at https://github.com/hegeldev/hegel-zoo/tree/main/targets/java/dnsjava. Let us know if you would like us to file the other bugs found and/or contribute the tests. NB the tests are currently LLM generated and probably not yet suitable for inclusion as is, but we're happy to help get them into a better state if you want them.\n","author":{"url":"https://github.com/DRMacIver","@type":"Person","name":"DRMacIver"},"datePublished":"2026-09-22T09:56:32Z","url":"https://github.com/dnsjava/dnsjava/issues/417"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:506a1735-3352-cd6e-da2b-25c56e9100c6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DE00:214A35:10BBA07:163B076:6B0655B1 |
| html-safe-nonce | 80b16df7c902982baa3c79a08ca214a57b0bc91dbfe8985957df0188af0e3abb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERTAwOjIxNEEzNToxMEJCQTA3OjE2M0IwNzY6NkIwNjU1QjEiLCJ2aXNpdG9yX2lkIjoiODYzMDUyMzkwMzA1MzU1MTAyNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | be87b5bd6dd7f1a978ce3c2e4023cdac25ac38b1885d7a2d9c8f33d64559c5da |
| hovercard-subject-tag | issue:5537970249 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/dnsjava/dnsjava/417/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a5dd9ab510c0a63f87b564179b3374b952f44b7bdf734a4fa12297152b0452b0/dnsjava/dnsjava/issues/417 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a5dd9ab510c0a63f87b564179b3374b952f44b7bdf734a4fa12297152b0452b0/dnsjava/dnsjava/issues/417 |
| og:image:alt | When Message.toWire(maxLength) has to drop answer records owned by the TSIG key's name, the TSIG record it writes cannot be parsed back (bad compression), and since the parser skips an unreadable a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | DRMacIver |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6324e6ac990fb6befbec840cc0e102a1071c339bfe8f9826bb12de2e3ba1d297 |
| turbo-cache-control | no-preview |
| go-import | github.com/dnsjava/dnsjava git https://github.com/dnsjava/dnsjava.git |
| octolytics-dimension-user_id | 6755615 |
| octolytics-dimension-user_login | dnsjava |
| octolytics-dimension-repository_id | 17084567 |
| octolytics-dimension-repository_nwo | dnsjava/dnsjava |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 17084567 |
| octolytics-dimension-repository_network_root_nwo | dnsjava/dnsjava |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7f0aa75f4141d440c6110dc31af7ea7797abb6c4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width