protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

EOF inside bytes field error occurs when exceeding specific length of bytes

Open slotherhouse opened this issue 3 years ago • 1 comments

What version of protobuf and what language are you using? Version v3.21.9 of the the google/protobuf composer package. Generated with libprotoc 3.17.0

Language: PHP

What operating system (Linux, Windows, ...) and version? Debian linux ( 4.19.0-22-amd64 #1 SMP Debian 4.19.260-1 (2022-09-29) x86_64 GNU/Linux )

What runtime / compiler are you using (e.g., python version or gcc version) Error has been confirmed with php7.3 / php7.4 / php8.1

What did you do? The error can be reproduced with the following .proto and php files, in a repository with protobuf installed through composer.

data.proto

syntax = "proto3";

message Message {
    SubMessage result = 1;
}

message SubMessage {
    oneof dataNullable {
        bytes data = 1;
    }
}

main.php

<?php

require_once './vendor/autoload.php';
require_once './GPBMetadata/Data.php';
require_once './Message.php';
require_once './SubMessage.php';

$subMsg = new \SubMessage();
$subMsg->setData(str_repeat('0', 33554423));
$msg = new \Message();
$msg->setResult($subMsg);

$recv = new \Message();
$recv->mergeFromString($msg->serializeToString());

Php protobuf classes generated with: protoc --php_out=./ ./data.proto

What did you expect to see Nothing, the script should execute without error.

What did you see instead? (Using php7.3) PHP Fatal error: Uncaught Google\Protobuf\Internal\GPBDecodeException: Error occurred during parsing: Unexpected EOF inside bytes field. in /home/x/php/vendor/google/protobuf/src/Google/Protobuf/Internal/Message.php:442 Stack trace: #0 /home/x/php/vendor/google/protobuf/src/Google/Protobuf/Internal/Message.php(515): Google\Protobuf\Internal\Message::parseFieldFromStreamNoTag(Object(Google\Protobuf\Internal\CodedInputStream), Object(Google\Protobuf\Internal\FieldDescriptor), NULL) #1 /home/x/php/vendor/google/protobuf/src/Google/Protobuf/Internal/Message.php(811): Google\Protobuf\Internal\Message->parseFieldFromStream(10, Object(Google\Protobuf\Internal\CodedInputStream), Object(Google\Protobuf\Internal\FieldDescriptor)) #2 /home/x/php/vendor/google/protobuf/src/Google/Protobuf/Internal/GPBWire.php(289): Google\Protobuf\Internal\Message->parseFromStream(Object(Google\Protobuf\Internal\CodedInputStream)) #3 /home/x/php/vendor/google/protobuf/src/Google/Protobuf/Internal/Message.php(435): Google\Protobuf\Internal\ in /home/x/php/vendor/google/protobuf/src/Google/Protobuf/Internal/Message.php on line 442

Anything else we should know about your project / environment The error occurs on a str_repeat of exactly 33554423 or more times 0, when adjusting to 33554422 no error occurs. The total strlen of the outer $msg when serialized to string is 33554433 ( Binary value of 10000000000000000000000001 )

slotherhouse avatar Dec 01 '22 15:12 slotherhouse

Is there an update on this item? I seem to have the same issue.

WarriorXK avatar Dec 14 '22 08:12 WarriorXK

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.

github-actions[bot] avatar Dec 27 '23 10:12 github-actions[bot]

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.

This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.

github-actions[bot] avatar Jan 10 '24 10:01 github-actions[bot]