TechnitiumSoftware/DnsServer · error · ArgumentException
Boot file name cannot exceed 127 bytes.
Error message
Boot file name cannot exceed 127 bytes.
What it means
Constructor argument guard in DhcpMessage: the boot file name (file) must be at most 127 ASCII bytes. RFC 2131 fixes the 'file' field at 128 bytes (127 usable + a null terminator); the constructor ASCII-encodes file and rejects a result of 128+ bytes. The check uses >= 128, so up to 127 bytes are allowed.
Source
Thrown at DnsServerCore/Dhcp/DhcpMessage.cs:159
if (sname != null)
{
_serverHostName = sname;
byte[] buffer = Encoding.ASCII.GetBytes(sname);
if (buffer.Length >= 64)
throw new ArgumentException("Server host name cannot exceed 63 bytes.", nameof(sname));
Buffer.BlockCopy(buffer, 0, _sname, 0, buffer.Length);
}
_file = new byte[128];
if (file != null)
{
_bootFileName = file;
byte[] buffer = Encoding.ASCII.GetBytes(file);
if (buffer.Length >= 128)
throw new ArgumentException("Boot file name cannot exceed 127 bytes.", nameof(file));
Buffer.BlockCopy(buffer, 0, _file, 0, buffer.Length);
}
_options = options;
foreach (DhcpOption option in _options)
{
if (option.Code == DhcpOptionCode.ServerIdentifier)
{
_serverIdentifier = option as ServerIdentifierOption;
break;
}
}
}
public DhcpMessage(Stream s)
{View on GitHub (pinned to d0484b6c1e)
Solutions
- Use a boot file path whose ASCII encoding is <= 127 bytes.
- Store only the path (not a full URL or embedded script) in the file field; move long payloads to DHCP options (e.g. option 66/67 or vendor options).
- Validate Encoding.ASCII.GetByteCount(file) < 128 before constructing.
- Shorten directory structure / use a shorter filename on the TFTP server.
Example fix
// before
string file = "https://tftp.example.corp.local/boot/very/deeply/nested/path/to/this/image/bootstrap-image-filename.bin"; // > 127 bytes
var msg = new DhcpMessage(op, htype, xid, secs, flags, ..., sname, file, opts); // throws [219]
// after: bare path within 127 bytes
string file = "/boot/pxelinux.0";
if (Encoding.ASCII.GetByteCount(file) >= 128) throw new InvalidOperationException("file too long");
var msg = new DhcpMessage(op, htype, xid, secs, flags, ..., sname, file, opts); Defensive patterns
Strategy: validation
Validate before calling
if (file is not null && Encoding.ASCII.GetByteCount(file) >= 128)
throw new ArgumentException("Boot file name (file) must be <= 127 ASCII bytes.", nameof(file));
var msg = new DhcpMessage(op, htype, xid, secs, flags, ciaddr, yiaddr, siaddr, giaddr, chaddr, sname, file, opts); Type guard
static bool IsValidBootFile(string file) =>
file is null || Encoding.ASCII.GetByteCount(file) < 128; Prevention
- Store only the boot file path in the file field, not a full URL or embedded script.
- Validate ASCII byte count < 128 before constructing.
- Move long payloads to DHCP options (e.g. option 66/67).
When it happens
Trigger: Calling the DhcpMessage constructor with a non-null file whose ASCII encoding is 128 or more bytes.
Common situations: A long boot image path with many directory segments; a full URL placed in the file field instead of a path; iPXE scripts/embedded data; a deeply nested TFTP path.
Related errors
- Client hardware address cannot exceed 16 bytes.
- Transaction ID must be 4 bytes.
- Seconds elapsed must be 2 bytes.
- Server host name cannot exceed 63 bytes.
- Address family not supported.
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/93704fca73a21241.
Report an issue: GitHub.