]> granicus.if.org Git - php/commitdiff
- Generate CRC32 in case not done in original file
authorMarcus Boerger <helly@php.net>
Mon, 22 Jan 2007 02:04:51 +0000 (02:04 +0000)
committerMarcus Boerger <helly@php.net>
Mon, 22 Jan 2007 02:04:51 +0000 (02:04 +0000)
ext/phar/phar.c

index f11b3f2e9689edea6e6b1507bc10b5a1af2b4a9f..0299f05e258d99ddf29cf7c01d6772eaa946af3d 100644 (file)
@@ -1678,10 +1678,22 @@ int phar_flush(phar_entry_data *data, char *user_stub, long len TSRMLS_DC) /* {{
                        entry->is_crc_checked = 1;
                        entry->compressed_filesize = entry->uncompressed_filesize;
                } else {
-                       if (-1 == php_stream_seek(oldfile, entry->offset_within_phar + data->phar->internal_file_start, SEEK_SET)) {
-                               if (oldfile) {
+                       if (!entry->is_crc_checked) {
+                               if (-1 == php_stream_seek(oldfile, entry->offset_within_phar + data->phar->internal_file_start, SEEK_SET)) {
                                        php_stream_close(oldfile);
+                                       php_stream_close(newfile);
+                                       php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "unable to seek to start of file \"%s\" while creating new phar \"%s\"", entry->filename, data->phar->fname);
+                                       return EOF;
+                               }
+                               newcrc32 = ~0;
+                               for (loc = entry->uncompressed_filesize; loc > 0; --loc) {
+                                       CRC32(newcrc32, php_stream_getc(oldfile));
                                }
+                               entry->crc32 = ~newcrc32;
+                               entry->is_crc_checked = 1;
+                       }
+                       if (-1 == php_stream_seek(oldfile, entry->offset_within_phar + data->phar->internal_file_start, SEEK_SET)) {
+                               php_stream_close(oldfile);
                                php_stream_close(newfile);
                                php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "unable to seek to start of file \"%s\" while creating new phar \"%s\"", entry->filename, data->phar->fname);
                                return EOF;