Protobuf Field Numbers Top Out at 2^29-1 (and the Encoder Silently Wraps Past It)
Field numbers in a protobuf schema are almost always small, so nobody thinks about the top of the range. The spec puts a ceiling on them, and the ceiling is not a round number. It is five hundred thirty six million eight hundred seventy thousand nine hundred eleven, which is two to the twenty ninth power minus one. I measured what enforces that number, what happens when you walk past it, and which tool in the chain notices. The short version: protoc guards the door, the JavaScript engine the tool at proto.datajutsu.com is built on does not, and the encoder fails in the worst way, which is to fail silently.
The ceiling comes out of the wire format itself. Every field starts with a tag, and the tag is the field number shifted left three bits with the wire type in the low bits, then written as a varint. The line the spec draws is exactly where the shifted number still fits in thirty two bits. The ceiling, shifted left three, lands at two to the thirty second minus eight, inside the limit. One number past the ceiling shifts to two to the thirty second, which overflows. Real protoc twenty five point three enforces it to the letter: a field at the ceiling compiles fine, one above it gets the exact error Field numbers cannot be greater than 536870911, and zero is rejected with Field numbers must be positive integers. There is also a second wall inside the range that most summaries skip: the numbers nineteen thousand through nineteen thousand nine hundred ninety nine are reserved for the protocol buffer library implementation, so a message you write cannot use them. That is a different mechanism from a reserved line in your own schema, which only blocks the numbers and names you wrote down, and is covered in the reserved ranges post.
The JavaScript parser is permissive where protoc is strict. I tested a sweep of ids across the range, the low ones, the reserved band, the exact ceiling, one past the ceiling, and up to two to the thirty second minus one, and every single one of them parsed clean, including zero and two to the twenty ninth, both of which protoc rejects. The only id it refuses is negative one, and then it tells you exactly why with illegal id. So a schema that parses clean in a browser tool is not proof protoc will take it. The directional claim holds on the side that matters: every file protoc accepts parses here, and the tool accepts extra shapes on top. The bytes are where the permissiveness stops mattering, because the wire facts in the wire format post do not know what your parser said yes to.
Here is the part that will bite you. The encoder, handed a field number at or above two to the twenty ninth, does not throw. It wraps around a thirty two bit number, the same overflow the ceiling is built to prevent. At the ceiling the tag is five bytes, f8ffffff0f, and the value rides out fine. One number past the ceiling and the tag comes out as a single zero byte, which is field zero, a tag the spec says cannot exist. I round tripped it: a message that declares its field at two to the twenty ninth, given the value five, encodes to the two bytes 0005, and decoding those same bytes under the same schema gives you an empty object. The value is gone and no error was raised. Two numbers past the ceiling and the tag is 08, which is field one with the value five. I fed those bytes to a schema that does have a field one and they landed in it as the value five. That is the failure mode nobody wants, because a value sitting in a neighboring field reads as plausible.
The decoder has its own wall, and it at least fails loudly. I built a stream by hand with a six byte tag, which is what a field number of two to the thirty second needs, and pointed a decoder at it. Whether the schema declared that field number or not, the walk died with index out of range: 9 + 10 > 9. The error carries its own arithmetic, the index it had reached plus the bytes it was trying to skip, compared against the length of the stream. It is the same error family as a truncated stream from the unknown field post, but the cause is not your stream, it is the tag. A five byte tag, the largest one the spec allows, skips through an unknown field walk without trouble. It is the sixth byte that breaks the math.
So the boundary is real on every side, and the implementations agree on the bytes. Real protoc encodes a value at the ceiling field to f8ffffff0f05, and the JavaScript engine produces the same five bytes for the same input, which you can check yourself in the tool at proto.datajutsu.com. The practical rule that falls out of this: real schemas live in the low thousands, and every interesting failure sits far past anything you will pick by hand. But when you are diffing a schema and a field number has jumped from the hundreds to the hundreds of millions, that is not a typo to accept, that is a number that will wrap around the encoder or break the decoder. The unknown field numbers post covers what a decoder does with numbers it does not know, and this is what it does with numbers it cannot fit.