Lines Matching refs:entry

161 static int phar_tar_process_metadata(phar_entry_info *entry, php_stream *fp) /* {{{ */  in phar_tar_process_metadata()  argument
167 metadata = (char *) safe_emalloc(1, entry->uncompressed_filesize, 1); in phar_tar_process_metadata()
169 read = php_stream_read(fp, metadata, entry->uncompressed_filesize); in phar_tar_process_metadata()
170 if (read != entry->uncompressed_filesize) { in phar_tar_process_metadata()
176 if (phar_parse_metadata(&metadata, &entry->metadata, entry->uncompressed_filesize) == FAILURE) { in phar_tar_process_metadata()
183 …if (entry->filename_len == sizeof(".phar/.metadata.bin")-1 && !memcmp(entry->filename, ".phar/.met… in phar_tar_process_metadata()
184 entry->phar->metadata = entry->metadata; in phar_tar_process_metadata()
185 ZVAL_UNDEF(&entry->metadata); in phar_tar_process_metadata()
186entry->filename_len >= sizeof(".phar/.metadata/") + sizeof("/.metadata.bin") - 1 && NULL != (mentr… in phar_tar_process_metadata()
188 mentry->metadata = entry->metadata; in phar_tar_process_metadata()
189 ZVAL_UNDEF(&entry->metadata); in phar_tar_process_metadata()
208 phar_entry_info entry = {0}; in phar_parse_tarfile() local
249 entry.is_tar = 1; in phar_parse_tarfile()
250 entry.is_crc_checked = 1; in phar_parse_tarfile()
251 entry.phar = myphar; in phar_parse_tarfile()
266 size = entry.uncompressed_filesize = entry.compressed_filesize = in phar_parse_tarfile()
356 entry.filename_len = entry.uncompressed_filesize; in phar_parse_tarfile()
359 if (entry.filename_len == UINT_MAX || entry.filename_len == 0) { in phar_parse_tarfile()
367 entry.filename = pemalloc(entry.filename_len+1, myphar->is_persistent); in phar_parse_tarfile()
369 read = php_stream_read(fp, entry.filename, entry.filename_len); in phar_parse_tarfile()
370 if (read != entry.filename_len) { in phar_parse_tarfile()
371 efree(entry.filename); in phar_parse_tarfile()
379 entry.filename[entry.filename_len] = '\0'; in phar_parse_tarfile()
387 efree(entry.filename); in phar_parse_tarfile()
399 efree(entry.filename); in phar_parse_tarfile()
426 entry.filename_len = i+j; in phar_parse_tarfile()
428 if (name[entry.filename_len - 1] == '/') { in phar_parse_tarfile()
430 entry.filename_len--; in phar_parse_tarfile()
432 entry.filename = pestrndup(name, entry.filename_len, myphar->is_persistent); in phar_parse_tarfile()
442 entry.filename_len = i; in phar_parse_tarfile()
443 entry.filename = pestrndup(hdr->name, i, myphar->is_persistent); in phar_parse_tarfile()
445 if (i > 0 && entry.filename[entry.filename_len - 1] == '/') { in phar_parse_tarfile()
447 entry.filename[entry.filename_len - 1] = '\0'; in phar_parse_tarfile()
448 entry.filename_len--; in phar_parse_tarfile()
453 phar_add_virtual_dirs(myphar, entry.filename, entry.filename_len); in phar_parse_tarfile()
457 … error: \"%s\" is a corrupted tar file (checksum mismatch of file \"%s\")", fname, entry.filename); in phar_parse_tarfile()
459 pefree(entry.filename, myphar->is_persistent); in phar_parse_tarfile()
465 entry.tar_type = ((old & (hdr->typeflag == '\0')) ? TAR_FILE : hdr->typeflag); in phar_parse_tarfile()
466 entry.offset = entry.offset_abs = pos; /* header_offset unused in tar */ in phar_parse_tarfile()
467 entry.fp_type = PHAR_FP; in phar_parse_tarfile()
468 entry.flags = phar_tar_number(hdr->mode, sizeof(hdr->mode)) & PHAR_ENT_PERM_MASK; in phar_parse_tarfile()
469 entry.timestamp = phar_tar_number(hdr->mtime, sizeof(hdr->mtime)); in phar_parse_tarfile()
470 entry.is_persistent = myphar->is_persistent; in phar_parse_tarfile()
472 if (old && entry.tar_type == TAR_FILE && S_ISDIR(entry.flags)) { in phar_parse_tarfile()
473 entry.tar_type = TAR_DIR; in phar_parse_tarfile()
476 if (entry.tar_type == TAR_DIR) { in phar_parse_tarfile()
477 entry.is_dir = 1; in phar_parse_tarfile()
479 entry.is_dir = 0; in phar_parse_tarfile()
482 entry.link = NULL; in phar_parse_tarfile()
486 if (entry.tar_type == TAR_LINK) { in phar_parse_tarfile()
491 pefree(entry.filename, entry.is_persistent); in phar_parse_tarfile()
496 entry.link = estrndup(hdr->linkname, linkname_len); in phar_parse_tarfile()
497 } else if (entry.tar_type == TAR_SYMLINK) { in phar_parse_tarfile()
498 entry.link = estrndup(hdr->linkname, linkname_len); in phar_parse_tarfile()
500 phar_set_inode(&entry); in phar_parse_tarfile()
502 …entry = zend_hash_str_update_mem(&myphar->manifest, entry.filename, entry.filename_len, (void*)&en… in phar_parse_tarfile()
505 if (entry.is_persistent) { in phar_parse_tarfile()
506 ++entry.manifest_pos; in phar_parse_tarfile()
509 …if (entry.filename_len >= sizeof(".phar/.metadata")-1 && !memcmp(entry.filename, ".phar/.metadata"… in phar_parse_tarfile()
512 …ar error: tar-based phar \"%s\" has invalid metadata in magic file \"%s\"", fname, entry.filename); in phar_parse_tarfile()
520 …if (!actual_alias && entry.filename_len == sizeof(".phar/alias.txt")-1 && !strncmp(entry.filename,… in phar_parse_tarfile()
698 static int phar_tar_writeheaders_int(phar_entry_info *entry, void *argument) /* {{{ */ in phar_tar_writeheaders_int() argument
705 if (entry->is_mounted) { in phar_tar_writeheaders_int()
709 if (entry->is_deleted) { in phar_tar_writeheaders_int()
710 if (entry->fp_refcount <= 0) { in phar_tar_writeheaders_int()
718 phar_add_virtual_dirs(entry->phar, entry->filename, entry->filename_len); in phar_tar_writeheaders_int()
721 if (entry->filename_len > 100) { in phar_tar_writeheaders_int()
723 if (entry->filename_len > 256) { in phar_tar_writeheaders_int()
725 …t be created, filename \"%s\" is too long for tar file format", entry->phar->fname, entry->filenam… in phar_tar_writeheaders_int()
729 boundary = entry->filename + entry->filename_len - 101; in phar_tar_writeheaders_int()
733 if (!*boundary || ((boundary - entry->filename) > 155)) { in phar_tar_writeheaders_int()
735 …t be created, filename \"%s\" is too long for tar file format", entry->phar->fname, entry->filenam… in phar_tar_writeheaders_int()
739 memcpy(header.prefix, entry->filename, boundary - entry->filename); in phar_tar_writeheaders_int()
740 memcpy(header.name, boundary + 1, entry->filename_len - (boundary + 1 - entry->filename)); in phar_tar_writeheaders_int()
742 memcpy(header.name, entry->filename, entry->filename_len); in phar_tar_writeheaders_int()
745 phar_tar_octal(header.mode, entry->flags & PHAR_ENT_PERM_MASK, sizeof(header.mode)-1); in phar_tar_writeheaders_int()
747 if (FAILURE == phar_tar_octal(header.size, entry->uncompressed_filesize, sizeof(header.size)-1)) { in phar_tar_writeheaders_int()
749 … be created, filename \"%s\" is too large for tar file format", entry->phar->fname, entry->filenam… in phar_tar_writeheaders_int()
754 if (FAILURE == phar_tar_octal(header.mtime, entry->timestamp, sizeof(header.mtime)-1)) { in phar_tar_writeheaders_int()
756 …fication time of file \"%s\" is too large for tar file format", entry->phar->fname, entry->filenam… in phar_tar_writeheaders_int()
762 header.typeflag = entry->tar_type; in phar_tar_writeheaders_int()
764 if (entry->link) { in phar_tar_writeheaders_int()
765 if (strlcpy(header.linkname, entry->link, sizeof(header.linkname)) >= sizeof(header.linkname)) { in phar_tar_writeheaders_int()
767 …ar \"%s\" cannot be created, link \"%s\" is too long for format", entry->phar->fname, entry->link); in phar_tar_writeheaders_int()
776 entry->crc32 = phar_tar_checksum((char *)&header, sizeof(header)); in phar_tar_writeheaders_int()
778 if (FAILURE == phar_tar_octal(header.checksum, entry->crc32, sizeof(header.checksum)-1)) { in phar_tar_writeheaders_int()
780 …ted, checksum of file \"%s\" is too large for tar file format", entry->phar->fname, entry->filenam… in phar_tar_writeheaders_int()
786 entry->header_offset = php_stream_tell(fp->new); in phar_tar_writeheaders_int()
790 …nnot be created, header for file \"%s\" could not be written", entry->phar->fname, entry->filenam… in phar_tar_writeheaders_int()
798 if (entry->uncompressed_filesize) { in phar_tar_writeheaders_int()
799 if (FAILURE == phar_open_entry_fp(entry, fp->error, 0)) { in phar_tar_writeheaders_int()
803 if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 0)) { in phar_tar_writeheaders_int()
805 …ed, contents of file \"%s\" could not be written, seek failed", entry->phar->fname, entry->filenam… in phar_tar_writeheaders_int()
810 …if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(entry, 0), fp->new, entry->uncompressed_f… in phar_tar_writeheaders_int()
812 …nnot be created, contents of file \"%s\" could not be written", entry->phar->fname, entry->filenam… in phar_tar_writeheaders_int()
818 …php_stream_write(fp->new, padding, ((entry->uncompressed_filesize +511)&~511) - entry->uncompresse… in phar_tar_writeheaders_int()
821 if (!entry->is_modified && entry->fp_refcount) { in phar_tar_writeheaders_int()
823 switch (entry->fp_type) { in phar_tar_writeheaders_int()
834 entry->is_modified = 0; in phar_tar_writeheaders_int()
836 if (entry->fp_type == PHAR_MOD && entry->fp != entry->phar->fp && entry->fp != entry->phar->ufp) { in phar_tar_writeheaders_int()
837 if (!entry->fp_refcount) { in phar_tar_writeheaders_int()
838 php_stream_close(entry->fp); in phar_tar_writeheaders_int()
840 entry->fp = NULL; in phar_tar_writeheaders_int()
843 entry->fp_type = PHAR_FP; in phar_tar_writeheaders_int()
846 entry->offset = entry->offset_abs = pos; in phar_tar_writeheaders_int()
857 int phar_tar_setmetadata(zval *metadata, phar_entry_info *entry, char **error) /* {{{ */ in phar_tar_setmetadata() argument
861 if (entry->metadata_str.s) { in phar_tar_setmetadata()
862 smart_str_free(&entry->metadata_str); in phar_tar_setmetadata()
865 entry->metadata_str.s = NULL; in phar_tar_setmetadata()
867 php_var_serialize(&entry->metadata_str, metadata, &metadata_hash); in phar_tar_setmetadata()
869entry->uncompressed_filesize = entry->compressed_filesize = entry->metadata_str.s ? ZSTR_LEN(entry in phar_tar_setmetadata()
871 if (entry->fp && entry->fp_type == PHAR_MOD) { in phar_tar_setmetadata()
872 php_stream_close(entry->fp); in phar_tar_setmetadata()
875 entry->fp_type = PHAR_MOD; in phar_tar_setmetadata()
876 entry->is_modified = 1; in phar_tar_setmetadata()
877 entry->fp = php_stream_fopen_tmpfile(); in phar_tar_setmetadata()
878 entry->offset = entry->offset_abs = 0; in phar_tar_setmetadata()
879 if (entry->fp == NULL) { in phar_tar_setmetadata()
883 …if (ZSTR_LEN(entry->metadata_str.s) != php_stream_write(entry->fp, ZSTR_VAL(entry->metadata_str.s)… in phar_tar_setmetadata()
884 …ror, 0, "phar tar error: unable to write metadata to magic metadata file \"%s\"", entry->filename); in phar_tar_setmetadata()
885 zend_hash_str_del(&(entry->phar->manifest), entry->filename, entry->filename_len); in phar_tar_setmetadata()
898 phar_entry_info *entry = (phar_entry_info *)Z_PTR_P(zv), *metadata, newentry = {0}; in phar_tar_setupmetadata() local
900 …if (entry->filename_len >= sizeof(".phar/.metadata") && !memcmp(entry->filename, ".phar/.metadata"… in phar_tar_setupmetadata()
901 …if (entry->filename_len == sizeof(".phar/.metadata.bin")-1 && !memcmp(entry->filename, ".phar/.met… in phar_tar_setupmetadata()
902 return phar_tar_setmetadata(&entry->phar->metadata, entry, error); in phar_tar_setupmetadata()
905entry->filename_len >= sizeof(".phar/.metadata/") + sizeof("/.metadata.bin") - 1 && !zend_hash_str… in phar_tar_setupmetadata()
913 if (!entry->is_modified) { in phar_tar_setupmetadata()
918 lookfor_len = spprintf(&lookfor, 0, ".phar/.metadata/%s/.metadata.bin", entry->filename); in phar_tar_setupmetadata()
920 if (Z_TYPE(entry->metadata) == IS_UNDEF) { in phar_tar_setupmetadata()
921 zend_hash_str_del(&(entry->phar->manifest), lookfor, lookfor_len); in phar_tar_setupmetadata()
926 if (NULL != (metadata = zend_hash_str_find_ptr(&(entry->phar->manifest), lookfor, lookfor_len))) { in phar_tar_setupmetadata()
928 ret = phar_tar_setmetadata(&entry->metadata, metadata, error); in phar_tar_setupmetadata()
935 newentry.phar = entry->phar; in phar_tar_setupmetadata()
939 …if (NULL == (metadata = zend_hash_str_add_mem(&(entry->phar->manifest), lookfor, lookfor_len, (voi… in phar_tar_setupmetadata()
941 … "phar tar error: unable to add magic metadata file to manifest for file \"%s\"", entry->filename); in phar_tar_setupmetadata()
945 return phar_tar_setmetadata(&entry->metadata, metadata, error); in phar_tar_setupmetadata()
951 phar_entry_info entry = {0}; in phar_tar_flush() local
959 entry.flags = PHAR_ENT_PERM_DEF_FILE; in phar_tar_flush()
960 entry.timestamp = time(NULL); in phar_tar_flush()
961 entry.is_modified = 1; in phar_tar_flush()
962 entry.is_crc_checked = 1; in phar_tar_flush()
963 entry.is_tar = 1; in phar_tar_flush()
964 entry.tar_type = '0'; in phar_tar_flush()
965 entry.phar = phar; in phar_tar_flush()
966 entry.fp_type = PHAR_MOD; in phar_tar_flush()
967 entry.fp = NULL; in phar_tar_flush()
968 entry.filename = NULL; in phar_tar_flush()
983 entry.filename = estrndup(".phar/alias.txt", sizeof(".phar/alias.txt")-1); in phar_tar_flush()
984 entry.filename_len = sizeof(".phar/alias.txt")-1; in phar_tar_flush()
985 entry.fp = php_stream_fopen_tmpfile(); in phar_tar_flush()
986 if (entry.fp == NULL) { in phar_tar_flush()
987 efree(entry.filename); in phar_tar_flush()
991 if (phar->alias_len != (int)php_stream_write(entry.fp, phar->alias, phar->alias_len)) { in phar_tar_flush()
995 php_stream_close(entry.fp); in phar_tar_flush()
996 efree(entry.filename); in phar_tar_flush()
1000 entry.uncompressed_filesize = phar->alias_len; in phar_tar_flush()
1002 … (NULL == zend_hash_str_update_mem(&phar->manifest, entry.filename, entry.filename_len, (void*)&en… in phar_tar_flush()
1006 php_stream_close(entry.fp); in phar_tar_flush()
1007 efree(entry.filename); in phar_tar_flush()
1074 entry.fp = php_stream_fopen_tmpfile(); in phar_tar_flush()
1075 if (entry.fp == NULL) { in phar_tar_flush()
1079 entry.uncompressed_filesize = len + 5; in phar_tar_flush()
1081 if ((size_t)len != php_stream_write(entry.fp, user_stub, len) in phar_tar_flush()
1082 || 5 != php_stream_write(entry.fp, " ?>\r\n", 5)) { in phar_tar_flush()
1089 php_stream_close(entry.fp); in phar_tar_flush()
1093 entry.filename = estrndup(".phar/stub.php", sizeof(".phar/stub.php")-1); in phar_tar_flush()
1094 entry.filename_len = sizeof(".phar/stub.php")-1; in phar_tar_flush()
1095 …zend_hash_str_update_mem(&phar->manifest, entry.filename, entry.filename_len, (void*)&entry, sizeo… in phar_tar_flush()
1102 entry.fp = php_stream_fopen_tmpfile(); in phar_tar_flush()
1103 if (entry.fp == NULL) { in phar_tar_flush()
1107 if (sizeof(newstub)-1 != php_stream_write(entry.fp, newstub, sizeof(newstub)-1)) { in phar_tar_flush()
1108 php_stream_close(entry.fp); in phar_tar_flush()
1115 entry.uncompressed_filesize = entry.compressed_filesize = sizeof(newstub) - 1; in phar_tar_flush()
1116 entry.filename = estrndup(".phar/stub.php", sizeof(".phar/stub.php")-1); in phar_tar_flush()
1117 entry.filename_len = sizeof(".phar/stub.php")-1; in phar_tar_flush()
1121 …if (NULL == zend_hash_str_add_mem(&phar->manifest, entry.filename, entry.filename_len, (void*)&ent… in phar_tar_flush()
1122 php_stream_close(entry.fp); in phar_tar_flush()
1123 efree(entry.filename); in phar_tar_flush()
1130 php_stream_close(entry.fp); in phar_tar_flush()
1131 efree(entry.filename); in phar_tar_flush()
1134 … (NULL == zend_hash_str_update_mem(&phar->manifest, entry.filename, entry.filename_len, (void*)&en… in phar_tar_flush()
1135 php_stream_close(entry.fp); in phar_tar_flush()
1136 efree(entry.filename); in phar_tar_flush()
1238 entry.filename = ".phar/signature.bin"; in phar_tar_flush()
1239 entry.filename_len = sizeof(".phar/signature.bin")-1; in phar_tar_flush()
1240 entry.fp = php_stream_fopen_tmpfile(); in phar_tar_flush()
1241 if (entry.fp == NULL) { in phar_tar_flush()
1257 …if (8 != (int)php_stream_write(entry.fp, sigbuf, 8) || signature_length != (int)php_stream_write(e… in phar_tar_flush()
1271 entry.uncompressed_filesize = entry.compressed_filesize = signature_length + 8; in phar_tar_flush()
1273 entry.filename_len = phar_tar_writeheaders_int(&entry, (void *)&pass); in phar_tar_flush()