Skip to content

Commit 63dcfb4

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: GHSA-96wq-48vp-hh57: [metaphone] Fix signed integer overflow of char array offset
2 parents 3e57595 + 3f6f38b commit 63dcfb4

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
@@ -126,9 +126,9 @@ static zend_always_inline char encode(char c) {
126126

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

@@ -168,7 +168,7 @@ static char Lookahead(char *word, int how_far)
168168
/* {{{ metaphone */
169169
static void metaphone(unsigned char *word, size_t word_len, zend_long max_phonemes, zend_string **phoned_word, int traditional)
170170
{
171-
int w_idx = 0; /* point in the phonization we're at. */
171+
size_t w_idx = 0; /* point in the phonization we're at. */
172172
size_t p_idx = 0; /* end of the phoned phrase */
173173
size_t max_buffer_len = 0; /* maximum length of the destination buffer */
174174
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)