X-Git-Url: https://git.tld-linux.org/?a=blobdiff_plain;f=php-systzdata.patch;h=a5a7b9d56c8a4df4d12f82f9700da69d9e601dd9;hb=3030f946716702832c7058fde5822e54b314df64;hp=f841e9bb609264de40e464dc596f0773af4cb02d;hpb=47130bb86ff82df6ba9ec83597ffeacabc1d888a;p=packages%2Fphp.git diff --git a/php-systzdata.patch b/php-systzdata.patch index f841e9b..a5a7b9d 100644 --- a/php-systzdata.patch +++ b/php-systzdata.patch @@ -1,11 +1,20 @@ Add support for use of the system timezone database, rather than embedding a copy. Discussed upstream but was not desired. +(Few) upstream reports: +https://bugs.php.net/bug.php?id=53320 +https://bugs.php.net/bug.php?id=54250 + History: +r13: adapt for upstream changes to use PHP allocator +r12: adapt for upstream changes for new zic +r11: use canonical names to avoid more case sensitivity issues + round lat/long from zone.tab towards zero per builtin db +r10: make timezone case insensitive r9: fix another compile error without --with-system-tzdata configured (Michael Heimpold) r8: fix compile error without --with-system-tzdata configured r7: improve check for valid timezone id to exclude directories -r6: fix fd leak in r5, fix country code/BC flag use in +r6: fix fd leak in r5, fix country code/BC flag use in timezone_identifiers_list() using system db, fix use of PECL timezonedb to override system db, r5: reverts addition of "System/Localtime" fake tzname. @@ -16,9 +25,10 @@ r3: fix a crash if /usr/share/zoneinfo doesn't exist (Raphael Geissert) r2: add filesystem trawl to set up name alias index r1: initial revision ---- a/ext/date/lib/parse_tz.c -+++ b/ext/date/lib/parse_tz.c -@@ -24,6 +24,16 @@ +diff -up php-7.0.0RC1/ext/date/lib/parse_tz.c.systzdata php-7.0.0RC1/ext/date/lib/parse_tz.c +--- php-7.0.0RC1/ext/date/lib/parse_tz.c.systzdata 2015-08-18 23:39:24.000000000 +0200 ++++ php-7.0.0RC1/ext/date/lib/parse_tz.c 2015-08-22 07:54:38.097258458 +0200 +@@ -20,6 +20,16 @@ #include "timelib.h" @@ -35,12 +45,12 @@ r1: initial revision #include #ifdef HAVE_LOCALE_H -@@ -35,7 +45,12 @@ - #else +@@ -32,8 +42,12 @@ #include #endif -+ + +#ifndef HAVE_SYSTEM_TZDATA + #define TIMELIB_SUPPORTS_V2DATA #include "timezonedb.h" +#endif + @@ -48,25 +58,19 @@ r1: initial revision #if (defined(__APPLE__) || defined(__APPLE_CC__)) && (defined(__BIG_ENDIAN__) || defined(__LITTLE_ENDIAN__)) # if defined(__LITTLE_ENDIAN__) -@@ -55,9 +70,14 @@ - - static void read_preamble(const unsigned char **tzf, timelib_tzinfo *tz) +@@ -55,6 +69,11 @@ static int read_preamble(const unsigned { -- /* skip ID */ -- *tzf += 4; -- -+ if (memcmp(tzf, "TZif", 4) == 0) { -+ *tzf += 20; -+ return; -+ } -+ -+ /* skip ID */ -+ *tzf += 4; -+ - /* read BC flag */ - tz->bc = (**tzf == '\1'); - *tzf += 1; -@@ -260,7 +280,397 @@ void timelib_dump_tzinfo(timelib_tzinfo + uint32_t version; + ++ if (memcmp(*tzf, "TZif", 4) == 0) { ++ *tzf += 20; ++ return 0; ++ } ++ + /* read ID */ + version = (*tzf)[3] - '0'; + *tzf += 4; +@@ -298,7 +317,418 @@ void timelib_dump_tzinfo(timelib_tzinfo } } @@ -80,7 +84,7 @@ r1: initial revision +#endif + +/* System timezone database pointer. */ -+static const timelib_tzdb *timezonedb_system = NULL; ++static const timelib_tzdb *timezonedb_system; + +/* Hash table entry for the cache of the zone.tab mapping table. */ +struct location_info { @@ -98,16 +102,17 @@ r1: initial revision + * prevent too many collisions. */ +#define LOCINFO_HASH_SIZE (1021) + ++/* Compute a case insensitive hash of str */ +static uint32_t tz_hash(const char *str) +{ + const unsigned char *p = (const unsigned char *)str; + uint32_t hash = 5381; + int c; -+ -+ while ((c = *p++) != '\0') { ++ ++ while ((c = tolower(*p++)) != '\0') { + hash = (hash << 5) ^ hash ^ c; + } -+ ++ + return hash % LOCINFO_HASH_SIZE; +} + @@ -163,7 +168,7 @@ r1: initial revision + /* Round to five decimal place, not because it's a good idea, + * but, because the builtin data uses rounded data, so, match + * that. */ -+ *result = round(v * sign * 100000.0) / 100000.0; ++ *result = trunc(v * sign * 100000.0) / 100000.0; + + return p; +} @@ -291,7 +296,7 @@ r1: initial revision +{ + const timelib_tzdb_index_entry *alpha = first, *beta = second; + -+ return strcmp(alpha->id, beta->id); ++ return strcasecmp(alpha->id, beta->id); +} + + @@ -429,6 +434,26 @@ r1: initial revision + return S_ISREG(st->st_mode) && st->st_size > 20; +} + ++/* To allow timezone names to be used case-insensitively, find the ++ * canonical name for this timezone, if possible. */ ++static const char *canonical_tzname(const char *timezone) ++{ ++ if (timezonedb_system) { ++ timelib_tzdb_index_entry *ent, lookup; ++ ++ lookup.id = (char *)timezone; ++ ++ ent = bsearch(&lookup, timezonedb_system->index, ++ timezonedb_system->index_size, sizeof lookup, ++ sysdbcmp); ++ if (ent) { ++ return ent->id; ++ } ++ } ++ ++ return timezone; ++} ++ +/* Return the mmap()ed tzfile if found, else NULL. On success, the + * length of the mapped data is placed in *length. */ +static char *map_tzfile(const char *timezone, size_t *length) @@ -442,7 +467,7 @@ r1: initial revision + return NULL; + } + -+ snprintf(fname, sizeof fname, ZONEINFO_PREFIX "/%s", timezone); ++ snprintf(fname, sizeof fname, ZONEINFO_PREFIX "/%s", canonical_tzname(timezone)); + + fd = open(fname, O_RDONLY); + if (fd == -1) { @@ -465,11 +490,11 @@ r1: initial revision { int left = 0, right = tzdb->index_size - 1; #ifdef HAVE_SETLOCALE -@@ -299,36 +709,128 @@ static int seek_to_tz_position(const uns +@@ -337,21 +767,88 @@ static int seek_to_tz_position(const uns return 0; } -+static int seek_to_tz_position(const unsigned char **tzf, char *timezone, ++static int seek_to_tz_position(const unsigned char **tzf, char *timezone, + char **map, size_t *maplen, + const timelib_tzdb *tzdb) +{ @@ -481,15 +506,14 @@ r1: initial revision + if (orig == NULL) { + return 0; + } -+ -+ (*tzf) = (unsigned char *)orig ; ++ ++ (*tzf) = (unsigned char *)orig; + *map = orig; -+ -+ return 1; ++ return 1; + } -+ else ++ else +#endif -+ { ++ { + return inmem_seek_to_tz_position(tzf, timezone, tzdb); + } +} @@ -504,11 +528,10 @@ r1: initial revision + tmp->data = NULL; + create_zone_index(tmp); + system_location_table = create_location_table(); -+ fake_data_segment(tmp, system_location_table); ++ fake_data_segment(tmp, system_location_table); + timezonedb_system = tmp; + } + -+ + return timezonedb_system; +#else return &timezonedb_builtin; @@ -532,38 +555,55 @@ r1: initial revision - return (seek_to_tz_position(&tzf, timezone, tzdb)); + +#ifdef HAVE_SYSTEM_TZDATA -+ if (tzdb == timezonedb_system) { -+ char fname[PATH_MAX]; -+ struct stat st; ++ if (tzdb == timezonedb_system) { ++ char fname[PATH_MAX]; ++ struct stat st; + -+ if (timezone[0] == '\0' || strstr(timezone, "..") != NULL) { -+ return 0; -+ } -+ -+ snprintf(fname, sizeof fname, ZONEINFO_PREFIX "/%s", timezone); -+ -+ return stat(fname, &st) == 0 && is_valid_tzfile(&st); -+ } ++ if (timezone[0] == '\0' || strstr(timezone, "..") != NULL) { ++ return 0; ++ } ++ ++ if (system_location_table) { ++ if (find_zone_info(system_location_table, timezone) != NULL) { ++ /* found in cache */ ++ return 1; ++ } ++ } ++ ++ snprintf(fname, sizeof fname, ZONEINFO_PREFIX "/%s", canonical_tzname(timezone)); ++ ++ return stat(fname, &st) == 0 && is_valid_tzfile(&st); ++ } +#endif + + return (inmem_seek_to_tz_position(&tzf, timezone, tzdb)); } + static void skip_64bit_preamble(const unsigned char **tzf, timelib_tzinfo *tz) +@@ -376,24 +873,54 @@ static void read_64bit_header(const unsi timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb) { const unsigned char *tzf; + char *memmap = NULL; + size_t maplen; timelib_tzinfo *tmp; + int version; - if (seek_to_tz_position(&tzf, timezone, tzdb)) { + if (seek_to_tz_position(&tzf, timezone, &memmap, &maplen, tzdb)) { tmp = timelib_tzinfo_ctor(timezone); - read_preamble(&tzf, tmp); + version = read_preamble(&tzf, tmp); read_header(&tzf, tmp); read_transistions(&tzf, tmp); read_types(&tzf, tmp); +- if (version == 2) { +- skip_64bit_preamble(&tzf, tmp); +- read_64bit_header(&tzf, tmp); +- skip_64bit_transistions(&tzf, tmp); +- skip_64bit_types(&tzf, tmp); +- skip_posix_string(&tzf, tmp); +- } - read_location(&tzf, tmp); + +#ifdef HAVE_SYSTEM_TZDATA @@ -574,8 +614,8 @@ r1: initial revision + * if possible. */ + + if ((li = find_zone_info(system_location_table, timezone)) != NULL) { -+ tmp->location.comments = strdup(li->comment); -+ strncpy(tmp->location.country_code, li->code, 2); ++ tmp->location.comments = timelib_strdup(li->comment); ++ strncpy(tmp->location.country_code, li->code, 2); + tmp->location.longitude = li->longitude; + tmp->location.latitude = li->latitude; + tmp->bc = 1; @@ -583,7 +623,7 @@ r1: initial revision + else { + strcpy(tmp->location.country_code, "??"); + tmp->bc = 0; -+ tmp->location.comments = strdup(""); ++ tmp->location.comments = timelib_strdup(""); + } + + /* Now done with the mmap segment - discard it. */ @@ -592,13 +632,21 @@ r1: initial revision +#endif + { + /* PHP-style - use the embedded info. */ ++ if (version == 2) { ++ skip_64bit_preamble(&tzf, tmp); ++ read_64bit_header(&tzf, tmp); ++ skip_64bit_transistions(&tzf, tmp); ++ skip_64bit_types(&tzf, tmp); ++ skip_posix_string(&tzf, tmp); ++ } + read_location(&tzf, tmp); -+ } ++ } } else { tmp = NULL; } ---- a/ext/date/lib/timelib.m4 -+++ b/ext/date/lib/timelib.m4 +diff -up php-7.0.0RC1/ext/date/lib/timelib.m4.systzdata php-7.0.0RC1/ext/date/lib/timelib.m4 +--- php-7.0.0RC1/ext/date/lib/timelib.m4.systzdata 2015-08-18 23:39:24.000000000 +0200 ++++ php-7.0.0RC1/ext/date/lib/timelib.m4 2015-08-22 07:47:34.854055364 +0200 @@ -78,3 +78,17 @@ stdlib.h dnl Check for strtoll, atoll