square / square/wire

Map Adapter cannot handle Value whose representation can be zero bytes

Open
#3,153 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
4.4k
Forks
627
Avg merge
3d 15m
Merged PRs (30d)
20

Description

Subj

If you use message like:

message ValidZeroPayload {
    float distance_meters = 2;
    reserved 1;
}

Wire will choke on parsing map with value initialized as:

ValidZeroPayload {
    distance_meters: 0.0
}

That's because it will be encoded as zero bytes due to zero being treated as non-presence in case of integers and floats

Therefore it triggers this check to fail:
https://github.com/square/wire/blob/master/wire-runtime/src/commonMain/kotlin/com/squareup/wire/ProtoAdapter.kt#L812
Even though message itself is legit in protobuf 3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in wire-runtime/src/commonMain/kotlin/com/squareup/wire/ProtoAdapter.kt at the check around line 812, and reproduce the issue with the ValidZeroPayload protobuf example. Verify that a map value whose valid protobuf representation is zero bytes can be parsed successfully, while malformed input remains rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.