Skip to content

ext/pcntl: Bump num_signals to uint16_t - #21347

Merged
NattyNarwhal merged 1 commit into
php:PHP-8.5from
NattyNarwhal:pcntl-overflow-8.5
Mar 9, 2026
Merged

ext/pcntl: Bump num_signals to uint16_t#21347
NattyNarwhal merged 1 commit into
php:PHP-8.5from
NattyNarwhal:pcntl-overflow-8.5

Conversation

@NattyNarwhal

Copy link
Copy Markdown
Member

On AIX, NSIG is def'd as SIGMAX64+1, and SIGMAX64 itself is def'd as 255:

$ grep -Rw SIGMAX64 /QOpenSys/usr/include/
/QOpenSys/usr/include/sys/signal.h:#define SIGMAX64 255
/QOpenSys/usr/include/sys/signal.h:#define SIGMAX SIGMAX64
/QOpenSys/usr/include/sys/signal.h:#define NSIG64 (SIGMAX64+1)

...this causes an overflow when we set num_signals from the value of NSIG, per GCC:

/rpmbuild/BUILD/php-8.5.3/ext/pcntl/pcntl.c:216:25: warning: large integer implicitly truncated to unsigned type [-Woverflow]
PCNTL_G(num_signals) = NSIG;
^~~~

...when we try to use pcntl to i.e. install a signal handler, we get an error from pcntl:

Fatal error: Uncaught ValueError: pcntl_signal(): Argument #1 ($signal) must be less than 0 in phar:///QOpenSys/pkgs/bin/composer/vendor/seld/signal-handler/src/SignalHandler.php:491

The easiest way to deal with this silly AIX behaviour is to just promote the storage size.

On AIX, NSIG is def'd as SIGMAX64+1, and SIGMAX64 itself is def'd as
255:
```
$ grep -Rw SIGMAX64 /QOpenSys/usr/include/
/QOpenSys/usr/include/sys/signal.h:#define SIGMAX64 255
/QOpenSys/usr/include/sys/signal.h:#define SIGMAX SIGMAX64
/QOpenSys/usr/include/sys/signal.h:#define NSIG64 (SIGMAX64+1)
```
...this causes an overflow when we set num_signals from the value of
NSIG, per GCC:
```
/rpmbuild/BUILD/php-8.5.3/ext/pcntl/pcntl.c:216:25: warning: large integer implicitly truncated to unsigned type [-Woverflow]
PCNTL_G(num_signals) = NSIG;
^~~~
```
...when we try to use pcntl to i.e. install a signal handler, we get an
error from pcntl:
```
Fatal error: Uncaught ValueError: pcntl_signal(): Argument #1 ($signal) must be less than 0 in phar:///QOpenSys/pkgs/bin/composer/vendor/seld/signal-handler/src/SignalHandler.php:491
```
The easiest way to deal with this silly AIX behaviour is to just promote
the storage size.
@devnexen

Copy link
Copy Markdown
Member

looks safe change, did you have a quick look with pahole or similar ?

@NattyNarwhal

Copy link
Copy Markdown
MemberAuthor

I haven't used pahole, no. I'm guessing this does slightly blow up the size of the structure, as the bools and previous uint8 would have been packed into 32 bits.

Comment threadext/pcntl/php_pcntl.h
bool async_signals;
uint8_t num_signals;
/* some OSes define NSIG to be > UINT8_MAX */
uint16_t num_signals;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds padding before num_signals. Just to confirm: This is a private header, right?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the only thing that references it is pcntl.c, yes. It shouldn't be installed either.

@NattyNarwhal
NattyNarwhal merged commit f38058d into php:PHP-8.5Mar 9, 2026
18 of 19 checks passed
NattyNarwhal added a commit that referenced this pull request Mar 9, 2026
* PHP-8.5:
Update NEWS for pcntl fix [skip ci]
ext/pcntl: Bump num_signals to uint16_t (#21347)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@NattyNarwhal@devnexen@iluuu1994