Skip to content

Commit ab97806

Browse files
TimWollaericmann
authored andcommitted
GHSA-96wq-48vp-hh57: [metaphone] Fix signed integer overflow of char array offset
Fixes GHSA-96wq-48vp-hh57 Fixes CVE-2026-7568
1 parent 4154618 commit ab97806

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

ext/standard/metaphone.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ static zend_always_inline char encode(char c) {
128128

129129
/* Allows us to safely look ahead an arbitrary # of letters */
130130
/* I probably could have just used strlen... */
131-
static char Lookahead(char *word, int how_far)
131+
static char Lookahead(char *word, size_t how_far)
132132
{
133-
int idx;
133+
size_t idx;
134134
for (idx = 0; word[idx] != '\0' && idx < how_far; idx++);
135135
/* Edge forward in the string... */
136136

@@ -170,7 +170,7 @@ static char Lookahead(char *word, int how_far)
170170
/* {{{ metaphone */
171171
static void metaphone(unsigned char *word, size_t word_len, zend_long max_phonemes, zend_string **phoned_word, int traditional)
172172
{
173-
int w_idx = 0; /* point in the phonization we're at. */
173+
size_t w_idx = 0; /* point in the phonization we're at. */
174174
size_t p_idx = 0; /* end of the phoned phrase */
175175
size_t max_buffer_len = 0; /* maximum length of the destination buffer */
176176
char curr_letter;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GHSA-96wq-48vp-hh57: signed integer overflow of char array offset
3+
--CREDITS--
4+
012git012
5+
--INI--
6+
memory_limit=3G
7+
--SKIPIF--
8+
<?php
9+
if (!getenv('RUN_RESOURCE_HEAVY_TESTS')) die('skip resource-heavy test');
10+
if (getenv('SKIP_SLOW_TESTS')) die('skip slow test');
11+
if (PHP_INT_SIZE != 8) echo 'skip 64-bit only';
12+
?>
13+
--FILE--
14+
<?php
15+
16+
$str = str_repeat('0', 2 * (1024 ** 3) - 2) . 'AE';
17+
metaphone($str, 1);
18+
19+
?>
20+
===DONE===
21+
--EXPECT--
22+
===DONE===

0 commit comments

Comments
 (0)