Skip to content

Commit dd77cfe

Browse files
TimWollasaundefined
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 df8ae9c commit dd77cfe

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
@@ -117,10 +117,10 @@ static const char _codes[26] =
117117

118118
/* Allows us to safely look ahead an arbitrary # of letters */
119119
/* I probably could have just used strlen... */
120-
static char Lookahead(char *word, int how_far)
120+
static char Lookahead(char *word, size_t how_far)
121121
{
122122
char letter_ahead = '\0'; /* null by default */
123-
int idx;
123+
size_t idx;
124124
for (idx = 0; word[idx] != '\0' && idx < how_far; idx++);
125125
/* Edge forward in the string... */
126126

@@ -161,7 +161,7 @@ static char Lookahead(char *word, int how_far)
161161
/* {{{ metaphone */
162162
static void metaphone(unsigned char *word, size_t word_len, zend_long max_phonemes, zend_string **phoned_word, int traditional)
163163
{
164-
int w_idx = 0; /* point in the phonization we're at. */
164+
size_t w_idx = 0; /* point in the phonization we're at. */
165165
size_t p_idx = 0; /* end of the phoned phrase */
166166
size_t max_buffer_len = 0; /* maximum length of the destination buffer */
167167
ZEND_ASSERT(word != NULL);
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)