Skip to content

Commit ed92da8

Browse files
authored
Refactor uncompress() loop in php_handle_swc() (GH-17574)
As is, MSVC raises C4334[1] to hint at a potential code issue. We could solve this with a cast, but actually the code is unclear as is because `factor` is not the factor, but rather the factor`s power. Thus we refactor the loop variant, and also fix the comment. [1] <https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4334>
1 parent 28751d3 commit ed92da8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ext/standard/image.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ static struct gfxinfo *php_handle_swc(php_stream * stream)
165165
long bits;
166166
unsigned char a[64];
167167
unsigned long len=64, szlength;
168-
int factor = 1,maxfactor = 16;
168+
int factor = 1,maxfactor = 1 << 15;
169169
int status = 0;
170170
unsigned char *b, *buf = NULL;
171171
zend_string *bufz;
@@ -197,13 +197,13 @@ static struct gfxinfo *php_handle_swc(php_stream * stream)
197197
/*
198198
* zlib::uncompress() wants to know the output data length
199199
* if none was given as a parameter
200-
* we try from input length * 2 up to input length * 2^8
200+
* we try from input length * 2 up to input length * 2^15
201201
* doubling it whenever it wasn't big enough
202-
* that should be eneugh for all real life cases
202+
* that should be enough for all real life cases
203203
*/
204204

205205
do {
206-
szlength = ZSTR_LEN(bufz) * (1<<factor++);
206+
szlength = ZSTR_LEN(bufz) * (factor <<= 1);
207207
buf = erealloc(buf, szlength);
208208
status = uncompress(buf, &szlength, (unsigned char *) ZSTR_VAL(bufz), ZSTR_LEN(bufz));
209209
} while ((status==Z_BUF_ERROR)&&(factor<maxfactor));

0 commit comments

Comments
 (0)