Skip to content

Harden PHP repeated field indexing and namespace option validation#27852

Open
Abhinav-143x wants to merge 1 commit into
protocolbuffers:mainfrom
Abhinav-143x:php-hardening-repeatedfield-namespace-validation
Open

Harden PHP repeated field indexing and namespace option validation#27852
Abhinav-143x wants to merge 1 commit into
protocolbuffers:mainfrom
Abhinav-143x:php-hardening-repeatedfield-namespace-validation

Conversation

@Abhinav-143x
Copy link
Copy Markdown

This PR adds defensive validation to two PHP code paths where malformed input can otherwise reach native runtime or generated-code boundaries.

First, the native PHP RepeatedField::offsetSet() path now explicitly rejects negative and out-of-range indexes before converting the assigned value and before casting the index for upb_Array_Set(). This makes offsetSet() consistent with the other ArrayAccess methods and prevents invalid user-provided indexes from reaching the native repeated-field setter path.

Second, the PHP generator now validates php_namespace and php_metadata_namespace before using those options to derive PHP namespaces and generated filenames. This prevents malformed schema options from being emitted into generated PHP namespace/file output. Existing valid forms remain accepted, including empty options, normal namespace segments such as Php\\Test, and the existing php_metadata_namespace = "\\" root metadata special case.

Tests run:

  • bazel test //src/google/protobuf/compiler/php:generator_unittest
  • bazel build //php:extension
  • bazel test //php:conformance_test_c
  • bazel test //php:conformance_test
  • bazel test //php:proto_staleness_test
  • bazel test //php:test_amalgamation_staleness

@Abhinav-143x Abhinav-143x requested a review from a team as a code owner June 6, 2026 18:50
@Abhinav-143x Abhinav-143x requested review from bshaffer and removed request for a team June 6, 2026 18:50
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.

1 participant