Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP: Error decoding with missing field (old message definition) #2552

Closed
NicklasWallgren opened this issue Dec 29, 2016 · 3 comments
Closed
Assignees
Milestone

Comments

@NicklasWallgren
Copy link
Contributor

It isn't possible to decode/parse using an old message definition. If a field is missing in the message definition the "parseFieldFromStream" will fail with a fatal error.

"You can add new fields to your message formats without breaking backwards-compatibility; old binaries simply ignore the new field when parsing."

parseFromStream()
$field = $this->desc->getFieldByNumber($number); // $field is null
...
parseFieldFromStream()
$field_type = $field->getType(); // fatal error

A dirty quick-fix is to check for null fields in the parseFromStream() method, and continue if encountered.

$number = GPBWire::getTagFieldNumber($tag);
$field = $this->desc->getFieldByNumber($number);

// Check whether we retrieved a known field
if ($field == null) {
    continue;
}

if (!$this->parseFieldFromStream($tag, $input, $field)) {
    return false;
}
@NicklasWallgren
Copy link
Contributor Author

NicklasWallgren@4f29e13

@TeBoring
Copy link
Contributor

@NicklasWallgren Thanks, could you send this pull request to 3.2.x branch and also add a test?

@TeBoring TeBoring added this to the v3.2.0 milestone Jan 10, 2017
@TeBoring
Copy link
Contributor

Fixed in 60d4f8a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants