Skip to content

descriptor: reject an editions file whose edition is outside the supported range - #798

Open
saloni-garg wants to merge 2 commits into
anthropics:mainfrom
saloni-garg:fix-unsupported-edition
Open

saloni-garg wants to merge 2 commits into
anthropics:mainfrom
saloni-garg:fix-unsupported-edition

Conversation

@saloni-garg

Copy link
Copy Markdown

Summary

Fixes #634. An editions file whose edition is outside EDITION_PROTO2 through EDITION_2024 linked without error and resolved its features with the edition 2023 defaults. That held both for defined values the pool does not support (EDITION_UNSTABLE, the *_TEST_ONLY values, EDITION_MAX, EDITION_LEGACY) and for numbers this version of buffa does not define at all, like a future edition 1002, which decoding keeps as an unknown field. The 2023 defaults are right for a later edition only while that edition changes no runtime feature default, which the pool cannot know. protoc and protobuf-go both reject an edition above their supported maximum.

Change

  • buffa-descriptor/src/pool.rs: the syntax check in add_file_descriptor_set now reads the file's edition number as written (a new edition_number helper replaces has_edition; an undefined number is recovered from the unknown fields, where the closed Edition enum leaves it). An unset number or EDITION_UNKNOWN is still PoolError::MissingEdition; any other number outside EDITION_PROTO2..=EDITION_2024 is the new PoolError::UnsupportedEdition { file, edition }.
  • One judgement call to flag: the proposed range starts at EDITION_PROTO2 (998), so EDITION_LEGACY (900) in an editions-syntax file is rejected too, even though features::for_edition maps it to the proto2 defaults for direct callers. Happy to carve it out if you would rather keep it.
  • The existing test editions_file_with_an_undefined_edition_number_links_with_2023_defaults pinned the lenient behaviour; it now asserts the rejection, including the error's Display text, and keeps its wire-level construction (a hand-written unknown field for edition 5000, encoded and decoded). New tests in buffa-descriptor/tests/pool_unsupported_edition.rs cover the defined-but-unsupported values, a wire-encoded undefined number (1002), the four supported editions still linking, the missing-edition cases, and the gate not applying to non-editions files.
  • The MissingEdition docs and the features::for_file doc mention the new rejection; a changelog fragment is under .changes/unreleased/.

This is independent of #797 (the relative type_name resolution fix); the two touch different parts of pool.rs.

Test report

Before the fix, a probe test linking editions files with EDITION_UNSTABLE, EDITION_1_TEST_ONLY and EDITION_MAX passed (all three linked) on unpatched main. After the fix:

cargo test -p buffa-descriptor --all-features   # 570 passed, 0 failed (standalone, without #797)
cargo clippy -p buffa-descriptor --all-features --all-targets   # clean

(buffa-codegen, buffa-build, buffa and buffa-types suites, 2222 tests, pass with the combined tree; this change adds a PoolError variant and narrows what the pool accepts, and nothing in those crates matches PoolError exhaustively.)

One heads-up: this repo has a CLA (CLA.md). I have not signed it, so the CLA check is Saloni's to complete if you want this merged.

This change was prepared with AI assistance; the repro and test results above were run and checked by the author.

@github-actions

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@saloni-garg
saloni-garg marked this pull request as ready for review October 26, 2026 05:12

This branch has not been deployed

No deployments
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.

descriptor: an editions file whose edition the pool does not define links with the edition 2023 defaults

1 participant