Skip to content

Rebase @launchql/protobufjs fork onto protobufjs 7.6.6 - #1

Merged
devin-ai-integration[bot] merged 154 commits into
masterfrom
devin/1795643894-rebase-launchql-protobufjs
Nov 25, 2026
Merged

devin-ai-integration[bot] merged 154 commits into
masterfrom
devin/1795643894-rebase-launchql-protobufjs

Conversation

@pyramation

@pyramation pyramation commented Nov 25, 2026 •

Copy link
Copy Markdown

Summary

Rebases the fork onto upstream protobufjs-v7.6.6 (cli 1.3.3), which picks up the 11 upstream security fixes listed in constructive-io/pgsql-parser#405. The package names stay the same (@launchql/protobufjs@7.6.6, @launchql/protobufjs-cli@1.3.3), and the fork's behavior is unchanged:

  • Field.prototype.applyJsonName() is restored in src/field.js and called from parse.js after each field, so fields are named by their json_name (select_stmt → SelectStmt).
  • The old constructor exception in Type.add is dropped: upstream Namespace.get now uses hasOwnProperty, so a field named constructor no longer collides.
  • The CLI requires @launchql/protobufjs and resolves bundled google/** imports from the installed scoped runtime.
  • tests/comp_json_name.js is new.

The branch is upstream 7.6.6 plus one fork commit. It also has an -s ours merge of the old master so it merges without a force-push. The diff against master is mostly the upstream 7.2.6 → 7.6.6 changes.

8.8.1 / 2.7.1 was not used: 8.x changes the encoding of an explicitly set proto3 enum zero (7.6.6 emits it, 8.8.1 drops it), which would change our wire output.

Verification

  • Fork test suite: 1872/1872 passing.
  • pgsql-parser linked against this build: all 114 generated reference files are byte-identical for PG 13–18, and codec field tuples match the old fork. PG 18 SELECT 42 and 312/312 fixture files round-trip. pg-proto-parser has 46 tests passing and the CLI 18.
  • The same json_name/round-trip tests fail on plain upstream protobufjs (Expected: "SelectStmt", Received: undefined).

After merge: publish @launchql/protobufjs first, then @launchql/protobufjs-cli. constructive-io/pgsql-parser#407 then moves to these versions.


libpg-query and parser opened this PR for Dan
Implemented in session Remove vulnerable protobufjs fork from pg-proto-parser
Review with Devin · Open in Devin Desktop


Summary by CodeRabbit

  • New Features
    • Added support for Protocol Buffers Edition 2023, including feature settings and descriptor conversion.
    • Added BigInt conversion for 64-bit values and CLI options for nullable field behavior.
    • Improved UTF-8 decoding and generated code handling for reserved names.
  • Bug Fixes
    • Strengthened validation of nested data and message boundaries during encoding and decoding.
    • Fixed handling of special property names, map keys, and malformed UTF-8.
  • Documentation
    • Updated installation, browser usage, conversion guidance, CLI options, and release history.

mkruskal-google and others added 30 commits May 9, 2024 20:34
* Add handling for extension range options

* Fix CI failures

* Fix more test issues
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…bufjs#2001)

* Fix the type of reserved field in IType

* Fix the type issue in src file
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Multi-line typedefs now generates valid type syntax
…this only sets the default of optional fields, it doesn't control whether a field is optional or not)
@luxor-code-review

luxor-code-review Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Review complete. 🟠 3 high · 🟡 4 medium

💬 Inline comments (7)

  • 🟠 Guard and camelCase-fix proto3_optional in descriptor conversion — index.js:461
  • 🟠 resolveAll throw in async finish bypasses callback — root.js:122
  • 🟠 Root FQN cache short-circuits scoped relative lookup — namespace.js:423
  • 🟡 parseSyntax accepts arbitrary invalid syntax strings — parse.js:285
  • 🟡 Required fields serialized as optional when edition unspecified — index.js:520
  • 🟡 Repeated enum/message options corrupt in descriptor conversion — index.js:897
  • 🟡 parse() result no longer includes syntax — parse.js:974

The change introduces editions feature resolution into the reflection layer and parser, extends descriptor conversion to carry editions fields, and adds null-semantics options to the CLI targets.

Files Change
src/parse.js, src/namespace.js, src/field.js, src/type.js Editions grammar parsing, feature resolution defaults, and jsonName/presence handling
src/root.js, src/roots.js, src/converter.js, ext/descriptor/index.js Descriptor round-trip updates for editions, proto3 optional, and resolveAll behavior
src/reader.js, src/writer.js, src/decoder.js, src/encoder.js, src/util/minimal.js Wire-runtime refactors including varint64 and bounds handling
cli/*, lib/codegen/index.js Static/proto/json-module target updates, --null-semantics option, name escaping
tests/*, bench/* New editions, decoder-bounds, CLI, and converter test coverage
.github/*, release-please-config.json, CHANGELOG.md, package.json Release automation and version metadata

Reviewed commit: d4ae316

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

Changes: protobuf.js runtime and Editions support

Layer / File(s) Summary
Edition and descriptor contracts
google/protobuf/descriptor.proto, google/protobuf/descriptor.json, tests/data/google/protobuf/descriptor.proto, tests/data/test.d.ts, tests/data/test.js
Descriptor schemas and generated declarations add edition, feature, visibility, extension-range, and annotation metadata.
Edition parsing and feature resolution
src/parse.js, src/object.js, src/field.js, src/enum.js, src/namespace.js, src/root.js, src/service.js, src/type.js, ext/descriptor/*, tests/feature_*, tests/api_*, tests/comp_*
Parsing, reflection objects, and descriptor conversion carry edition data and resolve inherited feature settings. Field presence, packed encoding, and delimited encoding use resolved features.
Bounded codecs and recursive conversion
src/encoder.js, src/decoder.js, src/reader.js, src/converter.js, src/verifier.js, src/wrappers.js, tests/data/*.js, tests/api_*, tests/node/api_load-sync.js
Runtime and generated codecs propagate recursion depth and validate bounded reads. Conversion adds BigInt handling and object validation. Tests cover recursion limits and decoder boundaries.
CLI generation and proto output
cli/pbjs.js, cli/pbts.js, cli/targets/*, cli/lib/tsd-jsdoc/publish.js, tests/cli.js
CLI generation adds --null-semantics, updates generated names and references, adjusts proto field and packed-option output, and invokes JSDoc with separate process arguments.
Utilities and bundled libraries
src/util*, lib/codegen/*, lib/eventemitter/*, lib/fetch/*, lib/utf8/*, lib/inquire/*
Utility and library changes update property safety, module loading, event listener storage, UTF-8 decoding, generated function names, and package contents.

Release, CI, and documentation

Layer / File(s) Summary
Release and package configuration
.github/workflows/release.yaml, .github/workflows/test.yml, .release-please-manifest.json, release-please-config.json, package.json, cli/package.json, lib/*/package.json
Release automation adds conditional package publishing. CI Node.js versions, package versions, scripts, dependencies, and release-please package entries are updated.
Documentation and benchmarks
README.md, CHANGELOG.md, cli/README.md, cli/CHANGELOG.md, bench/index.js
Project links, installation guidance, conversion documentation, CLI option documentation, release notes, and benchmark cases are updated.

Suggested reviewers: dcodeio

Change: Other

Merge Risk: High · up to d4ae3 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

This rebase brings in many upstream fixes, but it currently fails lint and introduces several behavior regressions: exported descriptors lose proto3 optional markers and required labels, the decoder can accept some malformed input, type lookup and service resolution behave differently, and piped CLI input generates code without required-field checks. These should be fixed before merging and releasing.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

Buf (1.74.0)

google/protobuf/descriptor.proto

fatal: unable to access 'https://github.com/constructive-io/protobuf.js.git/': Failed to connect to github.com:443 over proxy 127.0.0.1 after 0 ms: Could not connect to server
fatal: could not fetch 32794926253943991870af5d3b30436b80d76308 from promisor remote

CODERABBIT_BUF_COMPATIBILITY_PHASE=materialize-base

tests/data/cli/null-defaults-edition2023.proto

fatal: unable to access 'https://github.com/constructive-io/protobuf.js.git/': Failed to connect to github.com:443 over proxy 127.0.0.1 after 0 ms: Could not connect to server
fatal: could not fetch 32794926253943991870af5d3b30436b80d76308 from promisor remote

CODERABBIT_BUF_COMPATIBILITY_PHASE=materialize-base

tests/data/cli/null-defaults-proto3.proto

fatal: unable to access 'https://github.com/constructive-io/protobuf.js.git/': Failed to connect to github.com:443 over proxy 127.0.0.1 after 0 ms: Could not connect to server
fatal: could not fetch 32794926253943991870af5d3b30436b80d76308 from promisor remote

CODERABBIT_BUF_COMPATIBILITY_PHASE=materialize-base

  • 5 others

@devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@socket-security

socket-security Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedistanbul@​0.4.59810010050100
Updatedeslint@​8.57.0 ⏵ 8.22.097 +110010050100
Updated@​protobufjs/​utf8@​1.1.2 ⏵ 1.1.11001007384100
Updatedreflect-metadata@​0.1.14 ⏵ 0.1.131001001008080
Updated@​types/​node@​26.6.10 ⏵ 18.7.13100 +11008194 -2100
Updatedtape@​5.7.5 ⏵ 5.6.099 +1110010083 -9100
Updatedgoogle-protobuf@​3.21.2 ⏵ 3.21.098 -110010085100
Updated@​launchql/​protobufjs@​7.2.6N/AN/AN/AN/AN/A
Updatedjaguarjs-jsdoc@​0.0.1 ⏵ 0.0.1N/AN/AN/AN/AN/A

View full report

@socket-security

socket-security Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Priority Alert  (click "▶" to expand/collapse) Action
Low priority
Critical CVE: Babel vulnerable to arbitrary code execution when compiling specifically crafted malicious code in npm @babel/traverse

CVE: GHSA-67hx-6x53-jw92 Babel vulnerable to arbitrary code execution when compiling specifically crafted malicious code (CRITICAL)

Affected versions: < 7.23.2; >= 8.0.0-alpha.0 < 8.0.0-alpha.4

Patched version: 7.23.2

From: package-lock.json → npm/nyc@15.1.0 → npm/@babel/traverse@7.18.13

ℹ Read more on: This package | This alert | What is a critical CVE?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Remove or replace dependencies that include known critical CVEs. Consumers can use dependency overrides or npm audit fix --force to remove vulnerable dependencies.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/@babel/traverse@7.18.13. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn
Low priority
Protestware or unwanted behavior: npm es5-ext

Note: The script attempts to run a local post-install script, which could potentially contain malicious code. The error handling suggests that it is designed to fail silently, which is a common tactic in malicious scripts.

From: package-lock.json → npm/gulp@4.0.2 → npm/gulp-sourcemaps@3.0.0 → npm/es5-ext@0.10.62

ℹ Read more on: This package | This alert | What is protestware?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Consider that consuming this package may come along with functionality unrelated to its primary purpose.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/es5-ext@0.10.62. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn

View full report

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds protobuf editions support (feature resolution, edition 2023 parsing, descriptor round-tripping), null-defaults CLI options, decoder bounds tests, and release-please workflow automation across the runtime, CLI, and descriptor extensions.

Key findings

  • 🟠 Guard and camelCase-fix proto3_optional in descriptor conversion — index.js:461
  • 🟠 resolveAll throw in async finish bypasses callback — root.js:122
  • 🟠 Root FQN cache short-circuits scoped relative lookup — namespace.js:423
  • 🟡 parseSyntax accepts arbitrary invalid syntax strings — parse.js:285
  • 🟡 Required fields serialized as optional when edition unspecified — index.js:520
  • 🟡 Repeated enum/message options corrupt in descriptor conversion — index.js:897
  • 🟡 parse() result no longer includes syntax — parse.js:974

Comment thread ext/descriptor/index.js
Comment on lines 461 to +463
field.options = fromDescriptorOptions(descriptor.options, exports.FieldOptions);
if (descriptor.proto3_optional)
field.options.proto3_optional = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 bug · high

Guard and camelCase-fix proto3_optional in descriptor conversion

field.options.proto3_optional = true is assigned without ensuring field.options exists (ext/descriptor/index.js:462-463), and fromDescriptorOptions returns undefined when the descriptor carries no options message — the common case for a proto3 optional field — throwing TypeError on valid descriptor sets. The same block reads descriptor.proto3_optional, but the compiled FieldDescriptorProto class uses proto3Optional (google/protobuf/descriptor.json:322), so the flag is also never seen from decoded binary descriptors; the symmetric write in Field.prototype.toDescriptor (ext/descriptor/index.js:542-543) sets descriptor.proto3_optional, an unknown property that is silently dropped on binary encoding.

📋 Prompt for AI Agents

In ext/descriptor/index.js around lines 461-463, change if (descriptor.proto3_optional) to if (descriptor.proto3Optional) to match the compiled FieldDescriptorProto property (see google/protobuf/descriptor.json) and make the assignment null-safe: if (descriptor.proto3Optional) (field.options || (field.options = {})).proto3_optional = true;. In Field.prototype.toDescriptor at lines 542-543, change descriptor.proto3_optional = true to descriptor.proto3Optional = true so the flag survives binary descriptor encoding. Without this, protoc descriptor sets with proto3 optional fields crash Root.fromDescriptor or silently lose the optional marker.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is upstream protobufjs v7.6.6, byte-identical to the protobufjs-v7.6.6 tag. This PR only rebases the fork onto it and re-applies applyJsonName, so we're keeping upstream's behavior here rather than diverging the fork; any fix belongs upstream. Our use (pbjs static codegen for pg_query.proto) is verified byte-identical on PG 13–18.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood on the upstream-provenance constraint — but note the finding is about upstream code itself, not the rebase: in protobufjs v7.6.6, fromDescriptorOptions returns undefined when no options message is present, so field.options.proto3_optional = true throws on the common proto3-optional case, and the snake_case reads/writes don't match the compiled FieldDescriptorProto property (proto3Optional), so the flag is lost in binary descriptor round-trips. If byte-identical parity is the goal, the right move is to file/track this upstream, but the crash on valid protoc descriptor sets will remain in this fork until then. I'll leave the finding open unless you want it marked wontfix.

Comment thread src/parse.js
Comment on lines +285 to +286
if (edition < 2023)
throw illegal(edition, "syntax");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 bug · medium

parseSyntax accepts arbitrary invalid syntax strings

parseSyntax validates with if (edition < 2023) throw illegal(...) (src/parse.js:285-286). For any non-numeric string the comparison is NaN and false, so garbage like syntax = "bogus" is accepted, whereas the previous code accepted only "proto2"/"proto3". Unsupported numeric editions like "2024" also parse and only fail at resolve time with an unrelated "Unknown edition" error, losing the file/line diagnostic.

📋 Prompt for AI Agents

In src/parse.js parseSyntax (lines 282-290), the guard if (edition < 2023) throw illegal(...) passes for any non-numeric string (NaN comparison) and also accepts unsupported numeric editions like "2024". Replace it with an explicit whitelist: throw illegal(edition, "syntax") unless edition is "proto2", "proto3", or a numeric value in the supported editions list (reuse the array from parseEdition).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is upstream protobufjs v7.6.6, byte-identical to the protobufjs-v7.6.6 tag. This PR only rebases the fork onto it and re-applies applyJsonName, so we're keeping upstream's behavior here rather than diverging the fork; any fix belongs upstream. Our use (pbjs static codegen for pg_query.proto) is verified byte-identical on PG 13–18.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood — if this hunk is byte-identical to upstream protobufjs v7.6.6, deferring to upstream is a reasonable call for a tracking fork. That said, the original issue still stands on its own merits: the edition < 2023 guard lets non-numeric syntax strings like "bogus" through (NaN comparison is false) and admits unsupported editions like "2024", which the pre-upgrade code rejected at parse time. Worth filing upstream against protobufjs, since any consumer of stock v7.6.6 inherits the same weakened diagnostic. I'll leave this finding open (unresolved) rather than mark it fixed, since the code is unchanged.

Comment thread src/root.js
Comment on lines +122 to 127
if (root) {
root.resolveAll();
}
var cb = callback;
callback = null;
cb(err, root);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 bug · high

resolveAll throw in async finish bypasses callback

In the async load path, finish() now calls root.resolveAll() before invoking the user callback, but resolveAll can throw (e.g. unresolvable extensions at src/root.js:292-295). Since finish runs inside fs fetch callbacks, a throw means the callback is never invoked and the error escapes as an uncaught exception; the promise produced by util.asPromise(load, ...) never settles. Previously resolution was the caller's responsibility and errors surfaced through the callback/promise.

📋 Prompt for AI Agents

In src/root.js around lines 114-128, change finish(err, root) so the if (root) root.resolveAll(); call is wrapped in try/catch: on throw, pass the caught error to cb(err, undefined) instead of letting it escape the async fetch/setTimeout callback. Without this, a resolution failure during async Root#load becomes an uncaught exception and the returned promise never settles.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is upstream protobufjs v7.6.6, byte-identical to the protobufjs-v7.6.6 tag. This PR only rebases the fork onto it and re-applies applyJsonName, so we're keeping upstream's behavior here rather than diverging the fork; any fix belongs upstream. Our use (pbjs static codegen for pg_query.proto) is verified byte-identical on PG 13–18.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood that this hunk is byte-identical to upstream protobufjs v7.6.6 and you're intentionally not diverging — but note the behavior concern still stands on its own merits: in the async path (util.asPromise(load, ...)), a resolveAll throw (e.g. unresolvable extensions at src/root.js:292-295) escapes the fs callback as an uncaught exception and the returned promise never settles, since resolveAll() runs before cb(err, root) with no try/catch. If upstream parity is the priority, feel free to close this as won't-fix / file it upstream; otherwise wrapping the root.resolveAll() call and passing the caught error to cb would restore the previously documented error-through-callback contract. Marking as unresolved for now since no fix landed in this diff.

Comment thread src/namespace.js
Comment on lines +423 to +426
var found = this.root._fullyQualifiedObjects && this.root._fullyQualifiedObjects["." + flatPath];
if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
return found;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 bug · high

Root FQN cache short-circuits scoped relative lookup

The new early bailout in Namespace.lookup consults this.root._fullyQualifiedObjects["." + flatPath] for relative (non-.-prefixed) paths before any scoped search (src/namespace.js:423). When a root-level type shares a simple name with a nested type, lookup("Foo") from inside another namespace returns the root-level Foo even though a nearer scope also defines Foo, inverting protobuf's innermost-scope-first resolution. This is reachable from production paths: Field.prototype.resolve binds field type references via this.parent.lookup(...), so messages can silently bind to the wrong type whenever names collide across scopes.

📋 Prompt for AI Agents

In src/namespace.js at lines 422-426, restrict the early bailout this.root._fullyQualifiedObjects["." + flatPath] to absolute lookups (e.g. when this === this.root, or a flag set in the path[0] === "" branch) so relative lookups always perform the scoped _lookupImpl search and parent walk before falling back to root-level names, preserving protobuf's innermost-scope-first resolution.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is upstream protobufjs v7.6.6, byte-identical to the protobufjs-v7.6.6 tag. This PR only rebases the fork onto it and re-applies applyJsonName, so we're keeping upstream's behavior here rather than diverging the fork; any fix belongs upstream. Our use (pbjs static codegen for pg_query.proto) is verified byte-identical on PG 13–18.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood on provenance, but the bug is still visible in this hunk: the early bailout this.root._fullyQualifiedObjects["." + flatPath] runs before _lookupImpl and the parent walk, so relative lookups like lookup("Foo") still resolve to a root-level Foo over a nearer scoped one, inverting protobuf's innermost-scope-first resolution. Being byte-identical to upstream doesn't make it correct — if you don't want to diverge in this PR, upstreaming the fix (or carrying a small patch) is still needed to resolve this. Marking unresolved for now.

Comment thread ext/descriptor/index.js
Comment on lines +520 to 526
if (this.rule === "repeated") {
descriptor.label = 3;
} else if (this.required && edition === "proto2") {
descriptor.label = 2;
} else {
descriptor.label = 1;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 bug · medium

Required fields serialized as optional when edition unspecified

The rewritten rule logic in Field.prototype.toDescriptor only emits label = 2 (LABEL_REQUIRED) when this.required && edition === "proto2" (ext/descriptor/index.js:522). Root.prototype.toDescriptor(edition) and Type.prototype.toDescriptor(edition) default edition to undefined, so a plain root.toDescriptor() on a proto2 schema serializes every required field as LABEL_OPTIONAL, silently dropping the required marker on round-trip; the pre-change code always emitted label 2 for required fields.

📋 Prompt for AI Agents

In ext/descriptor/index.js at lines 519-526 (Field.prototype.toDescriptor), compute var effectiveEdition = edition || "proto2"; at the top of the method and use it in the === "proto2" label check and in the packed handling at lines 546-550, so a plain root.toDescriptor() on a proto2 schema keeps emitting LABEL_REQUIRED (label 2) for required fields as before.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is upstream protobufjs v7.6.6, byte-identical to the protobufjs-v7.6.6 tag. This PR only rebases the fork onto it and re-applies applyJsonName, so we're keeping upstream's behavior here rather than diverging the fork; any fix belongs upstream. Our use (pbjs static codegen for pg_query.proto) is verified byte-identical on PG 13–18.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood — if this hunk is byte-identical to upstream protobufjs v7.6.6 and the goal of this PR is to restore upstream parity, then keeping upstream's edition === "proto2" guard (and its undefined-default behavior) is a defensible choice rather than a regression introduced here. To be clear about the tradeoff: the fork's pre-rebase code did emit LABEL_REQUIRED for required fields on a plain root.toDescriptor(), so any in-repo callers relying on that (outside the verified pbjs path for pg_query.proto) would see required fields round-trip as LABEL_OPTIONAL. Given your verification that codegen output is byte-identical on PG 13–18 and that a real fix belongs upstream, I'll defer on this finding rather than ask you to diverge the fork — but it may be worth filing the effective-edition default (e.g. edition || "proto2") upstream if any consumer hits this.

Comment thread ext/descriptor/index.js
Comment on lines +897 to +903
if (field.resolvedType instanceof Type) {
val[newKey] = fromDescriptorOptionsRecursive(obj[key], field.resolvedType);
} else if(field.resolvedType instanceof Enum) {
val[newKey] = field.resolvedType.valuesById[obj[key]];
} else {
val[newKey] = obj[key];
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 bug · medium

Repeated enum/message options corrupt in descriptor conversion

fromDescriptorOptionsRecursive treats repeated option fields as singular: for an enum field it evaluates valuesById[obj[key]] (ext/descriptor/index.js:900) and for a message field recurses directly (line 898), but type.toObject(options) yields an array for repeated fields. valuesById[[1,2]] is undefined and message recursion into an array yields {}. Round-tripping a descriptor set with FieldOptions.targets or ExtensionRangeOptions.declaration set silently drops or corrupts those options.

📋 Prompt for AI Agents

In ext/descriptor/index.js in fromDescriptorOptionsRecursive (lines 889-906), handle repeated fields: when the field is repeated and Array.isArray(obj[key]), map each element through the same conversion used for singular values (field.resolvedType instanceof Enum ? field.resolvedType.valuesById[elem] : ... and per-element recursion for message types). Currently repeated enum options like FieldOptions.targets become valuesById[array] = undefined and repeated message options like ExtensionRangeOptions.declaration are recursed into as if they were a message.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is upstream protobufjs v7.6.6, byte-identical to the protobufjs-v7.6.6 tag. This PR only rebases the fork onto it and re-applies applyJsonName, so we're keeping upstream's behavior here rather than diverging the fork; any fix belongs upstream. Our use (pbjs static codegen for pg_query.proto) is verified byte-identical on PG 13–18.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood — if this is byte-identical to upstream protobufjs v7.6.6 and the intent is to stay unpatched upstream, that's a valid triage decision. However, the bug itself is still visible in this diff: fromDescriptorOptionsRecursive recurses into repeated message fields directly (ExtensionRangeOptions.declaration) and does valuesById[obj[key]] for repeated enums (FieldOptions.targets), which corrupts or drops those options on round-trip. Since there's no fix here, I'll leave the finding open rather than resolve it — if upstream addresses it, resolving then would be appropriate.

Comment thread src/parse.js
Comment on lines +974 to 978

parse.filename = null;
return {
"package" : pkg,
"imports" : imports,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 bug · medium

parse() result no longer includes syntax

The object returned by parse no longer contains the documented syntax property, and its JSDoc entry was removed (src/parse.js:974-978). External callers that read parsed.syntax to branch on proto2/proto3 now get undefined and silently misbehave; only the private root reflection objects carry edition information.

📋 Prompt for AI Agents

In src/parse.js around lines 974-978, restore a syntax property in the object returned by parse so existing consumers of parsed.syntax keep working: derive it from the local edition variable (return "proto2"/"proto3" for those values, and a representative value for numeric editions) and re-add the corresponding @property line in the JSDoc block near line 30.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is upstream protobufjs v7.6.6, byte-identical to the protobufjs-v7.6.6 tag. This PR only rebases the fork onto it and re-applies applyJsonName, so we're keeping upstream's behavior here rather than diverging the fork; any fix belongs upstream. Our use (pbjs static codegen for pg_query.proto) is verified byte-identical on PG 13–18.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the context — I see the hunk confirms the removal (- syntax : syntax) rather than a fix. Matching upstream v7.6.6 byte-for-byte is a defensible policy, but note the tradeoff: any downstream caller in this fork that reads parsed.syntax (e.g., to branch on proto2/proto3 in codegen paths) will now see undefined even if the fork's own current uses are safe. If you'd rather not diverge from upstream, consider filing an upstream issue to restore the property — but as shown in this diff, the finding itself is still unresolved.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@devin-ai-integration
devin-ai-integration Bot merged commit f6a1081 into master Nov 25, 2026
8 checks passed
pyramation added a commit that referenced this pull request Nov 25, 2026
…unchql-protobufjs

Rebase @launchql/protobufjs fork onto protobufjs 7.6.6
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.