From: Greg Beaver Date: Sat, 10 Dec 2005 00:00:00 +0000 (+0000) Subject: add crc checked flag, for slight speedup on multiple access to the same file X-Git-Tag: RELEASE_1_0_4~436 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fb5cff819dacadeb50f99eae96e9094d09a2dc09;p=php add crc checked flag, for slight speedup on multiple access to the same file --- diff --git a/ext/phar/phar.c b/ext/phar/phar.c index aa77831aac..38104e1488 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -260,6 +260,7 @@ PHP_METHOD(PHP_Archive, mapPhar) PHAR_GET_VAL(entry.timestamp) PHAR_GET_VAL(entry.offset_within_phar) PHAR_GET_VAL(entry.compressed_filesize) + entry.crc_checked = 0; if (entry.compressed_filesize < 9) { MAPPHAR_FAIL("internal corruption of phar \"%s\" (file size in phar is not large enough)") } @@ -672,16 +673,19 @@ PHP_PHAR_API php_stream * php_stream_phar_url_wrapper(php_stream_wrapper *wrappe php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file); } /* check crc32/filesize */ - status = phar_postprocess_file(idata->file, idata->internal_file->uncompressed_filesize, crc32, 0); - if (-1 == status) { - PHAR_ZLIB_ERROR - php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (crc32 mismatch on file \"%s\")", buffer, internal_file); - return NULL; - } - if (-2 == status) { - PHAR_ZLIB_ERROR - php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file); - return NULL; + if (!idata->internal_file->crc_checked) { + status = phar_postprocess_file(idata->file, idata->internal_file->uncompressed_filesize, crc32, 0); + if (-1 == status) { + PHAR_ZLIB_ERROR + php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (crc32 mismatch on file \"%s\")", buffer, internal_file); + return NULL; + } + if (-2 == status) { + PHAR_ZLIB_ERROR + php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file); + return NULL; + } + idata->internal_file->crc_checked = 1; } #else php_error_docref(NULL TSRMLS_CC, E_ERROR, "zlib extension must be enabled for compressed .phar files"); @@ -700,20 +704,23 @@ PHP_PHAR_API php_stream * php_stream_phar_url_wrapper(php_stream_wrapper *wrappe } php_stream_close(fp); /* check length, crc32 */ - status = phar_postprocess_file(idata->file, idata->internal_file->uncompressed_filesize, 0, 1); - if (-1 == status) { - efree(idata->file); - buffer = idata->data->file; - efree(idata); - php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (crc32 mismatch on file \"%s\")", buffer, internal_file); - return NULL; - } - if (-2 == status) { - efree(idata->file); - buffer = idata->data->file; - efree(idata); - php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file); - return NULL; + if (!idata->internal_file->crc_checked) { + status = phar_postprocess_file(idata->file, idata->internal_file->uncompressed_filesize, 0, 1); + if (-1 == status) { + efree(idata->file); + buffer = idata->data->file; + efree(idata); + php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (crc32 mismatch on file \"%s\")", buffer, internal_file); + return NULL; + } + if (-2 == status) { + efree(idata->file); + buffer = idata->data->file; + efree(idata); + php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file); + return NULL; + } + idata->internal_file->crc_checked = 1; } memmove(idata->file, idata->file + 8, idata->internal_file->uncompressed_filesize); } diff --git a/ext/phar/php_phar.h b/ext/phar/php_phar.h index d160e63669..3cbf2b6203 100644 --- a/ext/phar/php_phar.h +++ b/ext/phar/php_phar.h @@ -53,6 +53,7 @@ typedef struct _phar_manifest_entry { php_uint32 timestamp; php_uint32 offset_within_phar; php_uint32 compressed_filesize; + zend_bool crc_checked; } phar_manifest_entry; typedef struct _phar_file_data { diff --git a/ext/phar/tests/013.phpt b/ext/phar/tests/013.phpt index d4d08985a5..94d109912e 100644 --- a/ext/phar/tests/013.phpt +++ b/ext/phar/tests/013.phpt @@ -9,7 +9,7 @@ register_shutdown_function('cleanup'); $file = ""; -// compressed file length does not include 8 bytes for crc/file length and should +// filesize should be 1, and is 2 $manifest = pack('V', 1) . 'a' . pack('VVVV', 1, time(), 0, 9); $file .= pack('VV', strlen($manifest) + 4, 1) . $manifest . pack('VV', crc32('a'), 2) . 'a'; file_put_contents(dirname(__FILE__) . '/008_phar.php', $file);