Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/phar/phar.c
Original file line number Diff line number Diff line change
Expand Up @@ -2975,7 +2975,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv
4: metadata-len
+: metadata
*/
mytime = time(NULL);
mytime = source_date_epoch_time(NULL);
phar_set_32(entry_buffer, entry->uncompressed_filesize);
phar_set_32(entry_buffer+4, mytime);
phar_set_32(entry_buffer+8, entry->compressed_filesize);
Expand Down
15 changes: 15 additions & 0 deletions ext/phar/phar_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,21 @@ static inline zend_off_t phar_get_fp_offset(phar_entry_info *entry)
return PHAR_G(cached_fp)[entry->phar->phar_pos].manifest[entry->manifest_pos].offset;
}

static inline time_t source_date_epoch_time(time_t *tloc)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As pointed out by Ocramius, this argument seems not useful.

{
const char *sde;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please merge the declarations and assignments, we no longer do C89

time_t ts;

tsrm_env_lock();
sde = getenv("SOURCE_DATE_EPOCH");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use php_getenv, which will do the right thing on Windows and also take care of locking.

ts = (sde) ? strtoul(sde, NULL, 10) : time(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ts = (sde) ? strtoul(sde, NULL, 10) : time(0);
ts = (sde) ? strtoul(sde, NULL, 10) : time(NULL);

tsrm_env_unlock();
if (tloc) {
*tloc = ts;
}
Comment on lines +452 to +454
Copy link
Contributor

@Ocramius Ocramius Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the API of this function:

  • it returns a value?
  • it overwrites a reference, if given?
  • it uses an environment variable, if given?

I'd say that a rename (for clarity) would be a good idea, and the parameter can perhaps be always gone?

return ts;
}

#define PHAR_MIME_PHP '\0'
#define PHAR_MIME_PHPS '\1'
#define PHAR_MIME_OTHER '\2'
Expand Down
2 changes: 1 addition & 1 deletion ext/phar/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ static int phar_stream_flush(php_stream *stream) /* {{{ */
phar_entry_data *data = (phar_entry_data *) stream->abstract;

if (data->internal_file->is_modified) {
data->internal_file->timestamp = time(0);
data->internal_file->timestamp = source_date_epoch_time(0);
ret = phar_flush(data->phar, 0, 0, 0, &error);
if (error) {
php_stream_wrapper_log_error(stream->wrapper, REPORT_ERRORS, "%s", error);
Expand Down
2 changes: 1 addition & 1 deletion ext/phar/tar.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int
char halt_stub[] = "__HALT_COMPILER();";

entry.flags = PHAR_ENT_PERM_DEF_FILE;
entry.timestamp = time(NULL);
entry.timestamp = source_date_epoch_time(NULL);
entry.is_modified = 1;
entry.is_crc_checked = 1;
entry.is_tar = 1;
Expand Down
4 changes: 2 additions & 2 deletions ext/phar/zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static time_t phar_zip_d2u_time(char *cdtime, char *cddate) /* {{{ */
struct tm *tm, tmbuf;
time_t now;

now = time(NULL);
now = source_date_epoch_time(NULL);
tm = php_localtime_r(&now, &tmbuf);

tm->tm_year = ((ddate>>9)&127) + 1980 - 1900;
Expand Down Expand Up @@ -1221,7 +1221,7 @@ int phar_zip_flush(phar_archive_data *phar, char *user_stub, zend_long len, int

pass.error = &temperr;
entry.flags = PHAR_ENT_PERM_DEF_FILE;
entry.timestamp = time(NULL);
entry.timestamp = source_date_epoch_time(NULL);
entry.is_modified = 1;
entry.is_zip = 1;
entry.phar = phar;
Expand Down
Loading