[php-src] PHP-8.4.26: Fix heap-buffer-overflow in convert stream filters with NUL in line-break-chars

From: Date: Tue, 22 Sep 2026 14:40:27 +0000
Subject: [php-src] PHP-8.4.26: Fix heap-buffer-overflow in convert stream filters with NUL in line-break-chars
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-141428@lists.php.net to get a copy of this message
Author: geeknik (geeknik) Committer: Jakub Zelenka (bukka) Pusher: SakiTakamachi Date: 2026-09-19T16:12:22+02:00 Commit: https://github.com/php/php-src/commit/015c1cfdbb3304717b19e26a1cf59c4b6796a886 Raw diff: https://github.com/php/php-src/commit/015c1cfdbb3304717b19e26a1cf59c4b6796a886.diff Fix heap-buffer-overflow in convert stream filters with NUL in line-break-chars Use pestrndup() instead of pestrdup() when duplicating lbchars in the base64-encode, quoted-printable-encode, and quoted-printable-decode filter constructors. pestrdup() is strlen-based and truncates at the first NUL byte, but lbchars_len preserves the original length, causing an out-of-bounds read when the filter later copies lbchars_len bytes from the truncated allocation. Fixes GHSA-88hq-2827-7pg6. Changed paths: A ext/standard/tests/filters/ghsa-88hq-2827-7pg6.phpt M ext/standard/filters.c Diff: diff --git a/ext/standard/filters.c b/ext/standard/filters.c index 0c08600648cd..8f2d348f2e55 100644 --- a/ext/standard/filters.c +++ b/ext/standard/filters.c @@ -234,7 +234,7 @@ static php_conv_err_t php_conv_base64_encode_ctor(php_conv_base64_encode *inst, inst->line_ccnt = line_len; inst->line_len = line_len; if (lbchars != NULL) { - inst->lbchars = (lbchars_dup ? pestrdup(lbchars, persistent) : lbchars); + inst->lbchars = (lbchars_dup ? pestrndup(lbchars, lbchars_len, persistent) : lbchars); inst->lbchars_len = lbchars_len; } else { inst->lbchars = NULL; @@ -835,7 +835,7 @@ static php_conv_err_t php_conv_qprint_encode_ctor(php_conv_qprint_encode *inst, inst->line_ccnt = line_len; inst->line_len = line_len; if (lbchars != NULL) { - inst->lbchars = (lbchars_dup ? pestrdup(lbchars, persistent) : lbchars); + inst->lbchars = (lbchars_dup ? pestrndup(lbchars, lbchars_len, persistent) : lbchars); inst->lbchars_len = lbchars_len; } else { inst->lbchars = NULL; @@ -1048,7 +1048,7 @@ static php_conv_err_t php_conv_qprint_decode_ctor(php_conv_qprint_decode *inst, inst->next_char = 0; inst->lb_ptr = inst->lb_cnt = 0; if (lbchars != NULL) { - inst->lbchars = (lbchars_dup ? pestrdup(lbchars, persistent) : lbchars); + inst->lbchars = (lbchars_dup ? pestrndup(lbchars, lbchars_len, persistent) : lbchars); inst->lbchars_len = lbchars_len; } else { inst->lbchars = NULL; diff --git a/ext/standard/tests/filters/ghsa-88hq-2827-7pg6.phpt b/ext/standard/tests/filters/ghsa-88hq-2827-7pg6.phpt new file mode 100644 index 000000000000..84a85daefdb9 --- /dev/null +++ b/ext/standard/tests/filters/ghsa-88hq-2827-7pg6.phpt @@ -0,0 +1,27 @@ +--TEST-- +GHSA-88hq-2827-7pg6: OOB read in convert stream filters when line-break-chars contains NUL +--FILE-- +<?php + +// Test base64-encode: line-break-chars with embedded NUL must be preserved fully. +// Before the fix, pestrdup() truncated at the NUL, but lbchars_len kept the +// original length, causing a heap-buffer-overflow read during encoding. +$opts = ["line-length" => 4, "line-break-chars" => "\0X"]; +$fp = fopen("php://temp", "r+"); +fwrite($fp, str_repeat("A", 6)); +rewind($fp); +stream_filter_append($fp, "convert.base64-encode", STREAM_FILTER_READ, $opts); +$out = stream_get_contents($fp); +fclose($fp); + +// base64("AAAAAA") = "QUFBQUFB" (8 chars) +// With line-length=4: "QUFB" + "\0X" + "QUFB" +// Hex: 5155464200585155 4642 +echo bin2hex($out), "\n"; + +echo "Done\n"; + +?> +--EXPECT-- +51554642005851554642 +Done

« previous php.cvs (#141428) next »