protocolbuffers / protocolbuffers/protobuf

Parser erroneously allows whitespace in package declaration.

Open
#2,128 23 comments 0 reactions 1 assignee View on GitHub

@esrauchg is already working on this.

Since May 12, 2026.

bug c++ documentation keep open P3
Dominant language
C++
Stars
72k
Forks
16.3k
Avg merge
1d 17h
Merged PRs (30d)
140

Description

We had a case where protoc allowed a package declaration that had newlines in it but other tooling based on the spec failed to parse the file. I believe this should have failed to parse inside protoc as well.

Relevant parts of the spec:

package = "package" fullIdent ";"
fullIdent = ident { "." ident }
ident = letter { letter | decimalDigit | "_" }
letter = "A" … "Z" | "a" … "z"
decimalDigit = "0" … "9"

Example showing protoc allowing newlines:

$ echo "package example.

foo

;

message Foo {}" > test.proto

$ protoc --version
libprotoc 3.0.0

$ protoc --java_out=. test.proto
[libprotobuf WARNING google/protobuf/compiler/parser.cc:547] No syntax specified for the proto file: test.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)

$ tree
.
├── example
│   └── foo
│       └── Test.java
└── test.proto

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.