Repository navigation
Rebase @launchql/protobufjs fork onto protobufjs 7.6.6 - #1
devin-ai-integration[bot] merged 154 commits into
Conversation
* 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)
…for interface types)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
Review complete. 🟠 3 high · 🟡 4 medium 💬 Inline comments (7)
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.
Reviewed commit: d4ae316 |
|
Caution Review failedThe pull request is closed. Walkthrough
Change: Other Merge Risk:
|
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
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.
|
There was a problem hiding this comment.
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_optionalin descriptor conversion — index.js:461 - 🟠
resolveAllthrow in asyncfinishbypasses callback — root.js:122 - 🟠 Root FQN cache short-circuits scoped relative lookup — namespace.js:423
- 🟡
parseSyntaxaccepts 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 includessyntax— parse.js:974
| field.options = fromDescriptorOptions(descriptor.options, exports.FieldOptions); | ||
| if (descriptor.proto3_optional) | ||
| field.options.proto3_optional = true; |
There was a problem hiding this comment.
🟠 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| if (edition < 2023) | ||
| throw illegal(edition, "syntax"); |
There was a problem hiding this comment.
🟡 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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| if (root) { | ||
| root.resolveAll(); | ||
| } | ||
| var cb = callback; | ||
| callback = null; | ||
| cb(err, root); |
There was a problem hiding this comment.
🟠 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| var found = this.root._fullyQualifiedObjects && this.root._fullyQualifiedObjects["." + flatPath]; | ||
| if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) { | ||
| return found; | ||
| } |
There was a problem hiding this comment.
🟠 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| if (this.rule === "repeated") { | ||
| descriptor.label = 3; | ||
| } else if (this.required && edition === "proto2") { | ||
| descriptor.label = 2; | ||
| } else { | ||
| descriptor.label = 1; | ||
| } |
There was a problem hiding this comment.
🟡 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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]; | ||
| } |
There was a problem hiding this comment.
🟡 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
|
||
| parse.filename = null; | ||
| return { | ||
| "package" : pkg, | ||
| "imports" : imports, |
There was a problem hiding this comment.
🟡 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…unchql-protobufjs Rebase @launchql/protobufjs fork onto protobufjs 7.6.6
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 insrc/field.jsand called fromparse.jsafter each field, so fields are named by theirjson_name(select_stmt→SelectStmt).constructorexception inType.addis dropped: upstreamNamespace.getnow useshasOwnProperty, so a field namedconstructorno longer collides.@launchql/protobufjsand resolves bundledgoogle/**imports from the installed scoped runtime.tests/comp_json_name.jsis new.The branch is upstream 7.6.6 plus one fork commit. It also has an
-s oursmerge of the oldmasterso 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
SELECT 42and 312/312 fixture files round-trip. pg-proto-parser has 46 tests passing and the CLI 18.Expected: "SelectStmt",Received: undefined).After merge: publish
@launchql/protobufjsfirst, then@launchql/protobufjs-cli. constructive-io/pgsql-parser#407 then moves to these versions.Implemented in session Remove vulnerable protobufjs fork from pg-proto-parser
Review with Devin · Open in Devin Desktop
Summary by CodeRabbit