Repository navigation
Keep known fields with a mismatched wire type as unknown fields - #454
Closed
lukaszsamson wants to merge 1 commit into
Closed
lukaszsamson wants to merge 1 commit into
lukaszsamson wants to merge 1 commit into
Conversation
When a known field arrives with a wire type other than the one its type
uses, the decoder raised Protobuf.DecodeError ("wrong wire_type for
field ..."), failing the whole message. The reference implementations
(C++, Java, Go, upb) instead keep such a field as an unknown field and
continue decoding. Do the same: fall through to the unknown-field
clause, which preserves the bytes in __unknown_fields__ so re-encoding
is byte-identical.
Also only take the packed path for a packed? field when the value is
length-delimited. Previously a packed field arriving as fixed32/fixed64
was decoded as if it were packed data, yielding garbage values.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
|
@lukaszsamson I'm sorry but I’m not gonna accept patches that are generated with Claude and where the author didn't even take the time to tell me (as human to human) the point of the patch (other than linking to another AI generate issue). I have access to coding agents too so might as well throw one at this myself. Thanks! |
Author
|
@whatyouhide sorry for the clanker PR. Would you like a human made one? I do believe the patch is warranted and it solves a real problem. Alternatives I have are forking the lib, migrating to something else or hand hacking the generated stubs |
Collaborator
|
I’m happy to review something from you. If a robot writes the code I have zero issues but I’m not going to read slop (in PR descriptions or code comments or documentation) 🙃 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #453.
When a known field arrives with a wire type other than the one its type uses, the decoder raises
Protobuf.DecodeError("wrong wire_type for field ...") and the whole message fails. Go, Java, C++ and upb keep such a field as an unknown field and keep decoding; #453 has permalinks to each implementation.Changes
Protobuf.Decoder.handle_value/7: remove the raising clause. A known field whose wire type matches none of the clauses now falls through to the existing unknown-field handling. The value has already been consumed according to its own wire type, so the rest of the message decodes normally. The bytes go into__unknown_fields__, so re-encoding is byte-identical.packed?field when the value is length-delimited. Previously a packed field arriving as fixed32/fixed64 was decoded as if it were packed data, which produced garbage values. Packed fields still accept the unpacked encoding through the regularwire_type: ^wire_typeclause.encode(decode(bin)) == bin.mix test: 646 passed (2 skipped, 9 excluded).mix format --check-formattedis clean.I also checked it end to end on the real payload from the issue: a TRON Nile
BlockListExtentioncontaining a tx whoseTransaction.Contract.provider(bytes) is a varint. It decodes with the unmodified schema, the field lands in__unknown_fields__, and all 12 transaction hashes recomputed from the re-encodedTransaction.rawmatch their txids.I didn't run the conformance runner locally. The
ValidDataMap.*.WireTypeMismatchtests (RECOMMENDED) accept output equal to the C++ reference, which drops the unknown entry field and uses the default value; the new map-entry test asserts that result.🤖 Generated with Claude Code