protocolbuffers/protobuf

PHP Extension - Segmentation fault when serialize() is called on a protobuf message

Offen

#24.369 geöffnet am 08.11.2025

 (4 Kommentare) (1 Reaktion) (0 zugewiesene Personen)C++ (16.128 Forks)batch import
help wanted

Repository-Metriken

Stars
 (71.223 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 2T 11h) (185 gemergte PRs in 30 T)

Beschreibung

The PHP C extension segfaults when serialize() is called on a protobuf message.

[!IMPORTANT]
This is a unusual use case but the extension should not crash if a proto message is serialize by mistake.


What version of protobuf and what language are you using? Version: main Language: php OS: Linux

What did you do?

<?php
# serialize_segfault.php

require_once (dirname(__DIR__) . '/vendor/autoload.php');

use Foo\TestMessage;

$msg = new TestMessage(['optional_string' => "Hello, World!"]);

serialize($msg);
# Compile the extension 
./php/tests/compile_extension.sh

# Run script
php -d display_errors=on -dextension=../ext/google/protobuf/modules/protobuf.so  serialize_segfault.php

What did you expect to see

# no errors.

What did you see instead?

Segmentation fault

Patch here

Contributor Guide