Skip to content

imagetruecolortopalette() causes Segmentation Fault in Linux CLI only #21113

@neptune2

Description

@neptune2

Description

The following minimalized code (test.php):

<?php
$im = @imagecreatetruecolor(200, 50)
      or die('Cannot Initialize new GD image stream');

// Code allocating colors, filling background and adding text removed (no impact)

imagetruecolortopalette($im, false, 2); // This line initiates the potential CLI Segfault condition

// usleep(15000); // Uncomment this line to Prevent CLI Segfault !! (approx 0.015 sec or longer for slower system)

imagepng($im, "test.png");  // Works despite of Segfault. No impact on Segfault if commented out
<?php

Results in Segmentation fault .

To Reproduce:

/usr/bin/php test.php

Other observations:

  • No Segfault occurs when running as CGI - php initiated from browser (Apache/2.4.66 error.log)
  • No Segfault occurs on Windows (Win11, PHP 8.5.1 (cli) (built: Dec 16 2025 16:25:55) (NTS Visual C++ 2022 x64)
  • Uncommenting the usleep() line prevents the Segfault - even for much larger images
  • Changing the imagecreatetruecolor(200, 50) height arg to 15 or less prevents the Segfault (obviously not a viable workaround)

PHP Version

PHP 8.5.2 (cli) (built: Jan 18 2026 14:15:10) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.5.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.2, Copyright (c), by Zend Technologies

Also fails on 8.4.17 and 8.3.30.
Does **not** Segfault with PHP 7.4.3 (cli) (built: Mar 25 2025 18:57:03) ( NTS ) Ubuntu 20.04.6 i5-2400 CPU @ 3.10GHz

Operating System

Debian 12.2.0 (i5-7500T CPU @ 2.70GHz)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions