protocolbuffers / protocolbuffers/protobuf

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

Open
#24,369 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted
Dominant language
C++
Stars
72k
Forks
16.3k
Avg merge
1d 17h
Merged PRs (30d)
140

Description

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

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

Reproduce the crash with serialize_segfault.php using php/tests/compile_extension.sh and the provided PHP extension command. Inspect the PHP C extension path exercised by serialize($msg), then compare the behavior with the referenced patch. Done means the script completes without a segmentation fault or other errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.