Title: Message.toWire(int) truncates 12 octets early since 3.7.0 (the header is counted twice) · Issue #436 · dnsjava/dnsjava · GitHub
Open Graph Title: Message.toWire(int) truncates 12 octets early since 3.7.0 (the header is counted twice) · Issue #436 · dnsjava/dnsjava
X Title: Message.toWire(int) truncates 12 octets early since 3.7.0 (the header is counted twice) · Issue #436 · dnsjava/dnsjava
Description: Since 3.7.0, Message.toWire(int maxLength) truncates a message 12 octets before maxLength. A message that fits the limit exactly comes back with TC set and its sections cut. What we see We stepped the message size one octet at a time aga...
Open Graph Description: Since 3.7.0, Message.toWire(int maxLength) truncates a message 12 octets before maxLength. A message that fits the limit exactly comes back with TC set and its sections cut. What we see We stepped ...
X Description: Since 3.7.0, Message.toWire(int maxLength) truncates a message 12 octets before maxLength. A message that fits the limit exactly comes back with TC set and its sections cut. What we see We stepped ...
Opengraph URL: https://github.com/dnsjava/dnsjava/issues/436
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Message.toWire(int) truncates 12 octets early since 3.7.0 (the header is counted twice)","articleBody":"Since 3.7.0, `Message.toWire(int maxLength)` truncates a message 12 octets before `maxLength`. A message that fits the limit exactly comes back with TC set and its sections cut.\n\n### What we see\n\nWe stepped the message size one octet at a time against a fixed limit:\n\n| limit | 3.6.4: largest whole / smallest truncated | 3.7.1: largest whole / smallest truncated |\n|---|---|---|\n| 512, with and without OPT | 512 / 513 | 500 / 501 |\n| 1232, with and without OPT | 1232 / 1233 | 1220 / 1221 |\n\nOn a UDP server this means every answer in the last 12 octets of the client's advertised payload size goes out with TC=1, and the client retries over TCP for an answer that would have fitted. We see it in production: a 510-octet negative answer to a client advertising 512, and an 837-octet signed NXDOMAIN to a client advertising anything from 837 to 848, both come back truncated.\n\n### Why\n\nIn `Message.toWire(DNSOutput, Compression, int)`, the budget is reduced by the header first (Message.java:498 in 3.7.1):\n\n```java\nint tempMaxLength = maxLength - Header.LENGTH;\n```\n\nand `sectionToWire` then compares the absolute write position against that reduced budget (Message.java:470):\n\n```java\nif (out.current() > maxLength) { // maxLength here is tempMaxLength\n```\n\n`out.current()` already includes the 12 header octets written at `startpos`, so the header is counted twice. The TSIG and OPT reservations are fine; it is only the header.\n\nThis looks like it came in with 4f86d76c (\"Message: enforce toWire length\"), which was right to stop `toWire` from overshooting.\n\nA smaller related point: when the OPT record alone is larger than the budget, 3.7 throws `IllegalArgumentException`. A server rendering a response would rather get a truncated header plus question than an exception.\n\n### Suggested fix\n\nEither compare the bytes written since the header, `out.current() - startpos`, against `maxLength` less the TSIG and OPT reservations, or keep the absolute comparison and stop subtracting `Header.LENGTH`. Either way a message that fits `maxLength` exactly is rendered whole, and nothing ever exceeds `maxLength`, which is what 4f86d76c set out to guarantee.\n\nA test that renders messages of `maxLength - 1`, `maxLength` and `maxLength + 1` octets, with and without OPT and TSIG, and checks TC and the output length, would pin both directions.\n\nWe are working around it on our side by offering `toWire` the limit plus the measured hold-back, so there is no urgency from us. Happy to send a PR if that helps.\n\nThanks for dnsjava.\n\nKaveh Ranjbar\nWhisper Security\n","author":{"url":"https://github.com/kakooch","@type":"Person","name":"kakooch"},"datePublished":"2026-11-16T18:44:15Z","url":"https://github.com/dnsjava/dnsjava/issues/436"}
| 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:a13e225b-3fb1-f32b-ad18-da0bf51e2bb7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A75A:3CBF9:85BFB1:AC8EB5:6B062BC4 |
| html-safe-nonce | 7046b2f7d448d25dcda46c36652ff9990df9ea418d34ee4476fe22c8c06c758e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNzVBOjNDQkY5Ojg1QkZCMTpBQzhFQjU6NkIwNjJCQzQiLCJ2aXNpdG9yX2lkIjoiMTUxNzk2NDQ4NjQyNTA2MjM0MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4253554db337801f8d7735d16e0970ac02691b18678fa806e3d312267f2a3a21 |
| hovercard-subject-tag | issue:6428199345 |
| 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/436/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9367bf805d64f52ed42ccbf4c59f587ffd3a63475831a2ca5709aa7670e2e48d/dnsjava/dnsjava/issues/436 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9367bf805d64f52ed42ccbf4c59f587ffd3a63475831a2ca5709aa7670e2e48d/dnsjava/dnsjava/issues/436 |
| og:image:alt | Since 3.7.0, Message.toWire(int maxLength) truncates a message 12 octets before maxLength. A message that fits the limit exactly comes back with TC set and its sections cut. What we see We stepped ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kakooch |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7f961de5dd5c5d4aca24d33f8b3ffb3fb8b2ef53d0a4f32f01f0a790e512f6d3 |
| 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 | 494ea0bb1e0feef734a83e2628697647755e8864 |
| 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