Skip to content

Commit a1d4595

Browse files
committed
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 phpGH-16161.
1 parent 4d32402 commit a1d4595

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ PHP NEWS
55
- DOM:
66
. Added Dom\Element::$outerHTML. (nielsdos)
77

8+
- Output:
9+
. Fixed calculation of aligned buffer size. (cmb)
10+
811
- PDO_PGSQL:
912
. Added Iterable support for PDO::pgsqlCopyFromArray. (KentarouTakeda)
1013
. Implement GH-15387 Pdo\Pgsql::setAttribute(PDO::ATTR_PREFETCH, 0) or

main/php_output.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ typedef enum _php_output_handler_hook_t {
8181
} php_output_handler_hook_t;
8282

8383
#define PHP_OUTPUT_HANDLER_INITBUF_SIZE(s) \
84-
( ((s) > 1) ? \
85-
(s) + PHP_OUTPUT_HANDLER_ALIGNTO_SIZE - ((s) % (PHP_OUTPUT_HANDLER_ALIGNTO_SIZE)) : \
84+
( ((s) > 0) ? \
85+
ZEND_MM_ALIGNED_SIZE_EX(s, PHP_OUTPUT_HANDLER_ALIGNTO_SIZE) : \
8686
PHP_OUTPUT_HANDLER_DEFAULT_SIZE \
8787
)
8888
#define PHP_OUTPUT_HANDLER_ALIGNTO_SIZE 0x1000

tests/output/gh16135.phpt

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
GH-16135: output buffer over-allocated for aligned chunk sizes
3+
--FILE--
4+
<?php
5+
ob_start(null, 0);
6+
ob_start(null, 1);
7+
ob_start(null, 2);
8+
ob_start(null, 8191);
9+
ob_start(null, 8192);
10+
ob_start(null, 8193);
11+
var_dump(array_map(fn ($s) => $s["buffer_size"], ob_get_status(true)));
12+
?>
13+
--EXPECT--
14+
array(6) {
15+
[0]=>
16+
int(16384)
17+
[1]=>
18+
int(4096)
19+
[2]=>
20+
int(4096)
21+
[3]=>
22+
int(8192)
23+
[4]=>
24+
int(8192)
25+
[5]=>
26+
int(12288)
27+
}

0 commit comments

Comments
 (0)