Fix calculation of aligned buffer size

As is, for requested size which are already aligned, we over-allocate,
so we fix this.  We also fix the allocation for chunk size 1.

This issue has been reported by @kkmuffme.

Thanks to @iluuu1994 for improving the fix!

Closes GH-16161.
This commit is contained in:
Christoph M. Becker 2024-10-03 12:24:36 +02:00
parent 4d3240261d
commit a1d4595d65
No known key found for this signature in database
GPG key ID: D66C9593118BCCB6
3 changed files with 32 additions and 2 deletions

View file

@ -81,8 +81,8 @@ typedef enum _php_output_handler_hook_t {
} php_output_handler_hook_t;
#define PHP_OUTPUT_HANDLER_INITBUF_SIZE(s) \
( ((s) > 1) ? \
(s) + PHP_OUTPUT_HANDLER_ALIGNTO_SIZE - ((s) % (PHP_OUTPUT_HANDLER_ALIGNTO_SIZE)) : \
( ((s) > 0) ? \
ZEND_MM_ALIGNED_SIZE_EX(s, PHP_OUTPUT_HANDLER_ALIGNTO_SIZE) : \
PHP_OUTPUT_HANDLER_DEFAULT_SIZE \
)
#define PHP_OUTPUT_HANDLER_ALIGNTO_SIZE 0x1000