Skip to content

Fix codegen panic on messages containing nested extend blocks#181

Merged
huntsman90 merged 3 commits into
dropbox:mainfrom
huntsman90:fix-nested-extension-walk
May 26, 2026
Merged

Fix codegen panic on messages containing nested extend blocks#181
huntsman90 merged 3 commits into
dropbox:mainfrom
huntsman90:fix-nested-extension-walk

Conversation

@huntsman90

Copy link
Copy Markdown
Contributor

Summary

pb-jelly-gen's message walker (_walk_message in codegen.rs) panicked with called Option::unwrap() on a None value whenever it encountered a message containing a nested extend block.

The walker was looking up a field named "extension_type" on DescriptorProto, but the actual field for nested extensions is named "extension" (number 6) — see google/protobuf/descriptor.proto. get_field("extension_type") returned None, and the immediate .unwrap() panicked.

The file-level walker (_walk_file) already used the correct field name, so top-level extend blocks were unaffected. Only nested extends triggered the bug.

Why this surfaced now

The bug was dormant because no existing pb-test fixture exercised a nested extend block. It fires on real-world protos — most notably upstream protobuf v29's google/protobuf/sample_messages_edition.proto, which nests extends inside MessageSetCorrectExtension*. Anyone pulling protobuf v29 protos into a pb-jelly-gen build hits the panic immediately.

Test plan

  • cd pb-test/pb_test_gen && cargo run — codegen succeeds
  • cd pb-test && cargo test — integration tests pass
  • Confirmed reverting only the one-line fix re-introduces the
    panic on the new fixture, proving the test catches the
    regression.

`_walk_message` in pb-jelly-gen looked up a non-existent field
"extension_type" on `DescriptorProto`. The actual field for nested
extensions is named "extension" (number 6), per
google/protobuf/descriptor.proto. The bug was dormant because no
existing pb-test fixture had a nested `extend` block, but it fires on
real-world editions 2023 protos such as upstream
google/protobuf/sample_messages_edition.proto, which nest extends
inside `MessageSetCorrectExtension*`.

The file-level walker (`_walk_file`) already used the correct field
name; only the per-message walker was wrong.

Adds a regression proto (`pb-test/.../nested_extensions.proto`)
containing a message with a nested extend block. Without the fix,
running pb_test_gen panics at codegen.rs with
`called Option::unwrap() on a None value`; with the fix, codegen and
the integration test pass.

Co-authored-by: Cursor <cursoragent@cursor.com>
@CLAassistant

CLAassistant commented May 5, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

huntsman90 and others added 2 commits May 5, 2026 21:51
Co-authored-by: Cursor <cursoragent@cursor.com>
The verify_generated_files test (run with VALIDATE=1 in CI) compares
generated Rust against .expected snapshots checked into the repo.
Adding the new nested_extensions.proto fixture without its snapshot
caused CI to fail with NotFound when reading the missing
nested_extensions.rs.expected file.

Generate the missing snapshot and update lib.rs.expected to declare
the new module.

Co-authored-by: Cursor <cursoragent@cursor.com>
@huntsman90 huntsman90 added this pull request to the merge queue May 26, 2026
Merged via the queue into dropbox:main with commit dcbe283 May 26, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants