From: Greg Beaver Date: Wed, 16 Apr 2008 19:48:31 +0000 (+0000) Subject: load entire end of zip instead of weird 8k looping, logic is much simpler, and it... X-Git-Tag: RELEASE_2_0_0b1~344 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=159e39d81d90804c12db89d6b3b559cec6334e45;p=php load entire end of zip instead of weird 8k looping, logic is much simpler, and it's only 65k instead of 8k --- diff --git a/ext/phar/zip.c b/ext/phar/zip.c index 9e0ddce9e7..29e4bbbe4a 100644 --- a/ext/phar/zip.c +++ b/ext/phar/zip.c @@ -143,13 +143,14 @@ static void phar_zip_u2d_time(time_t time, php_uint16 *dtime, php_uint16 *ddate) */ int phar_open_zipfile(php_stream *fp, char *fname, int fname_len, char *alias, int alias_len, phar_archive_data** pphar, char **error TSRMLS_DC) /* {{{ */ { - char buf[8192], *metadata; phar_zip_dir_end locator; + char buf[sizeof(locator) + 65536], *metadata; long size; size_t read; php_uint16 i; phar_archive_data *mydata = NULL; phar_entry_info entry = {0}; + char *p = buf; size = php_stream_tell(fp); if (size > sizeof(locator) + 65536) { @@ -162,32 +163,16 @@ int phar_open_zipfile(php_stream *fp, char *fname, int fname_len, char *alias, i } else { php_stream_seek(fp, 0, SEEK_SET); } - do { - char *p = buf; - if (!(read = php_stream_read(fp, buf, 8192))) { - php_stream_close(fp); - return FAILURE; - } - if (*p == 'P' && !memcmp(p + 1, "K\5\6", 3)) { - goto copybuf; - } - while ((p=(char *) memchr(p + 1, 'P', (size_t)(buf - (p+1) + 8192 - 4 + 1))) != NULL) { - if (!memcmp(p + 1, "K\5\6", 3)) { - if (p - buf < sizeof(locator)) { - /* didn't read in the whole thing, back up */ - php_stream_seek(fp, 8192 - (p - buf), SEEK_CUR); - if (sizeof(locator) != php_stream_read(fp, (char *) &locator, sizeof(locator))) { - php_stream_close(fp); - return FAILURE; - } - } else { -copybuf: - memcpy((void *)&locator, (void *) p, sizeof(locator)); - } - goto foundit; - } + if (!(read = php_stream_read(fp, buf, size))) { + php_stream_close(fp); + return FAILURE; + } + while ((p=(char *) memchr(p + 1, 'P', (size_t)(buf - (p+1) + sizeof(locator) + 65536 - 4 + 1))) != NULL) { + if (!memcmp(p + 1, "K\5\6", 3)) { + memcpy((void *)&locator, (void *) p, sizeof(locator)); + goto foundit; } - } while (read == 8192); + } php_stream_close(fp); return FAILURE; foundit: