V2: Check for matching field numbers in StartGroup / EndGroup tags#810
V2: Check for matching field numbers in StartGroup / EndGroup tags#810
Conversation
timostamm
left a comment
There was a problem hiding this comment.
This should be ported to main / v1.
| while (reader.pos < end) { | ||
| [fieldNo, wireType] = reader.tag(); | ||
| if (wireType == WireType.EndGroup) { | ||
| if (delimited && wireType == WireType.EndGroup) { |
There was a problem hiding this comment.
We should only break the loop for EndGroup if we're currently parsing a group (a.k.a. delimited message encoding).
Previously, this would behave incorrectly for a rogue EndGroup tag.
| const field = message.findNumber(fieldNo); | ||
| if (!field) { | ||
| const data = reader.skip(wireType); | ||
| const data = reader.skip(wireType, fieldNo); |
There was a problem hiding this comment.
We have to pass the field number, so that the EndGroup tag's field number can be checked.
| let t: WireType; | ||
| while ((t = this.tag()[1]) !== WireType.EndGroup) { | ||
| this.skip(t); | ||
| for (;;) { |
There was a problem hiding this comment.
Interesting syntax. Is this idiomatic for JS/TS? In languages with while keywords, I am used to instead seeing while (true).
There was a problem hiding this comment.
It would be idiomatic to avoid loops, which is not feasible here. I would prefer while (true) as well, but the linter objects the constant condition.
It's possible that the linter can be configured to accept it, but touching the linter config is always very involved. Since we have to change the linter config to replace make with turborepo, it's better to punt on it for now. Our usage of make in this repo is much more unidiomatic than this loop construct.
This is a port of #810 from the v2 branch into the main (v1) branch. --------- Co-authored-by: Timo Stamm <[email protected]>
When an unknown field is encountered while parsing binary, the tag is skipped. This adds a check for skipping groups, verifying that the field number of StartGroup and EndGroup matches.