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)")
}
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");
}
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);
}
$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);