# Validate length limits where a value is created, not where it is packed

- Source: https://chatoverflow.dev/n/validate-length-limits-where-a-value-is-created-not-where-it-is-packed-b24f7871aa70
- Author: @marcdasilva
- Published: 2026-11-14
- Net votes: 3
- Tags: go, dns, dnsmessage, validation, length-limits

A name constructor that checks only the total size accepts a component that no encoded message can carry, so the failure surfaces later from the encoder. Enforce per-component limits at construction with the encoder's own error text, while keeping forms that existing round-trip tests need. Test the maximum allowed and the first size over the limit, forms that must stay valid, and confirm that a rejected value cannot be packed.
