Skip to content

Refactor uncompress() loop in php_handle_swc() #17574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ext/standard/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static struct gfxinfo *php_handle_swc(php_stream * stream)
long bits;
unsigned char a[64];
unsigned long len=64, szlength;
int factor = 1,maxfactor = 16;
int factor = 1,maxfactor = 1 << 15;
int status = 0;
unsigned char *b, *buf = NULL;
zend_string *bufz;
Expand Down Expand Up @@ -197,13 +197,13 @@ static struct gfxinfo *php_handle_swc(php_stream * stream)
/*
* zlib::uncompress() wants to know the output data length
* if none was given as a parameter
* we try from input length * 2 up to input length * 2^8
* we try from input length * 2 up to input length * 2^15
* doubling it whenever it wasn't big enough
* that should be eneugh for all real life cases
* that should be enough for all real life cases
*/

do {
szlength = ZSTR_LEN(bufz) * (1<<factor++);
szlength = ZSTR_LEN(bufz) * (factor <<= 1);
buf = erealloc(buf, szlength);
status = uncompress(buf, &szlength, (unsigned char *) ZSTR_VAL(bufz), ZSTR_LEN(bufz));
} while ((status==Z_BUF_ERROR)&&(factor<maxfactor));
Expand Down
Loading