1
0
mirror of https://github.com/php/php-src.git synced 2026-04-28 10:43:30 +02:00

add crc checked flag, for slight speedup on multiple access to the same file

This commit is contained in:
Greg Beaver
2005-12-10 00:00:00 +00:00
parent e1d98926ba
commit fb5cff819d
3 changed files with 33 additions and 25 deletions
+31 -24
View File
@@ -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);
}
+1
View File
@@ -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 {
+1 -1
View File
@@ -9,7 +9,7 @@ register_shutdown_function('cleanup');
$file = "<?php
PHP_Archive::mapPhar(5, 'hio', false);
__HALT_COMPILER(); ?>";
// 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);