]> git.pld-linux.org Git - packages/php.git/blobdiff - php-systzdata.patch
up to php-7.2.0RC6, likely last RC
[packages/php.git] / php-systzdata.patch
index a33ef0861e4d54702e0b9a92103deb214aed5c6b..63ba1d8f4e71f348982e6fdb99e03e6a9d578ee6 100644 (file)
@@ -1,7 +1,17 @@
+# License: MIT
+# http://opensource.org/licenses/MIT
+
 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:
+r15: adapt for timelib 2017.05beta7 (in 7.2.0RC1)
+r14: improve check for valid tz file
+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
@@ -20,11 +30,12 @@ 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
 
---- php-7.0.0RC1/ext/date/lib/parse_tz.c~      2015-08-27 12:06:04.000000000 +0300
-+++ php-7.0.0RC1/ext/date/lib/parse_tz.c       2015-08-27 12:08:08.706661229 +0300
-@@ -20,6 +20,16 @@
+diff -up ./ext/date/lib/parse_tz.c.systzdata ./ext/date/lib/parse_tz.c
+--- ./ext/date/lib/parse_tz.c.systzdata        2017-08-22 09:40:38.000000000 +0200
++++ ./ext/date/lib/parse_tz.c  2017-08-22 12:16:00.370298079 +0200
+@@ -25,8 +25,21 @@
  #include "timelib.h"
+ #include "timelib_private.h"
  
 +#ifdef HAVE_SYSTEM_TZDATA
 +#include <sys/mman.h>
@@ -34,16 +45,9 @@ r1: initial revision
 +#include <unistd.h>
 +
 +#include "php_scandir.h"
-+#endif
 +
- #include <stdio.h>
- #ifdef HAVE_LOCALE_H
-@@ -43,7 +43,11 @@
- #endif
++#else
  #define TIMELIB_SUPPORTS_V2DATA
-+#ifndef HAVE_SYSTEM_TZDATA
  #include "timezonedb.h"
 +#endif
 +
@@ -51,7 +55,7 @@ r1: initial revision
  
  #if (defined(__APPLE__) || defined(__APPLE_CC__)) && (defined(__BIG_ENDIAN__) || defined(__LITTLE_ENDIAN__))
  # if defined(__LITTLE_ENDIAN__)
-@@ -53,6 +68,10 @@ static int read_preamble(const unsigned
+@@ -67,6 +80,11 @@ static int read_php_preamble(const unsig
  {
        uint32_t version;
  
@@ -59,10 +63,11 @@ r1: initial revision
 +              *tzf += 20;
 +              return 0;
 +      }
++
        /* read ID */
        version = (*tzf)[3] - '0';
        *tzf += 4;
-@@ -296,7 +315,418 @@ void timelib_dump_tzinfo(timelib_tzinfo
+@@ -374,7 +392,429 @@ void timelib_dump_tzinfo(timelib_tzinfo
        }
  }
  
@@ -100,11 +105,11 @@ r1: initial revision
 +    const unsigned char *p = (const unsigned char *)str;
 +    uint32_t hash = 5381;
 +    int c;
-+    
++
 +    while ((c = tolower(*p++)) != '\0') {
 +        hash = (hash << 5) ^ hash ^ c;
 +    }
-+    
++
 +    return hash % LOCINFO_HASH_SIZE;
 +}
 +
@@ -281,6 +286,7 @@ r1: initial revision
 +              && strcmp(ent->d_name, "posix") != 0
 +              && strcmp(ent->d_name, "posixrules") != 0
 +              && strcmp(ent->d_name, "right") != 0
++              && strstr(ent->d_name, ".list") == NULL
 +              && strstr(ent->d_name, ".tab") == NULL;
 +}
 +
@@ -421,8 +427,18 @@ r1: initial revision
 +
 +/* Returns true if the passed-in stat structure describes a
 + * probably-valid timezone file. */
-+static int is_valid_tzfile(const struct stat *st)
++static int is_valid_tzfile(const struct stat *st, int fd)
 +{
++      if (fd) {
++              char buf[20];
++              if (read(fd, buf, 20)!=20) {
++                      return 0;
++              }
++              lseek(fd, SEEK_SET, 0);
++              if (memcmp(buf, "TZif", 4)) {
++                      return 0;
++              }
++      }
 +      return S_ISREG(st->st_mode) && st->st_size > 20;
 +}
 +
@@ -432,9 +448,9 @@ r1: initial revision
 +{
 +    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);
@@ -460,11 +476,11 @@ r1: initial revision
 +      }
 +
 +      snprintf(fname, sizeof fname, ZONEINFO_PREFIX "/%s", canonical_tzname(timezone));
-+      
++
 +      fd = open(fname, O_RDONLY);
 +      if (fd == -1) {
 +              return NULL;
-+      } else if (fstat(fd, &st) != 0 || !is_valid_tzfile(&st)) {
++      } else if (fstat(fd, &st) != 0 || !is_valid_tzfile(&st, fd)) {
 +              close(fd);
 +              return NULL;
 +      }
@@ -482,7 +498,7 @@ r1: initial revision
  {
        int left = 0, right = tzdb->index_size - 1;
  #ifdef HAVE_SETLOCALE
-@@ -335,21 +765,87 @@ static int seek_to_tz_position(const uns
+@@ -419,9 +859,48 @@ static int seek_to_tz_position(const uns
        return 0;
  }
  
@@ -499,9 +515,9 @@ r1: initial revision
 +                      return 0;
 +              }
 +
-+              (*tzf) = (unsigned char *)orig ;
++              (*tzf) = (unsigned char *)orig;
 +              *map = orig;
-+              return 1;
++        return 1;
 +      }
 +      else
 +#endif
@@ -530,17 +546,8 @@ r1: initial revision
 +#endif
  }
  
- const timelib_tzdb_index_entry *timelib_timezone_builtin_identifiers_list(int *count)
- {
-+#ifdef HAVE_SYSTEM_TZDATA
-+      *count = timezonedb_system->index_size;
-+      return timezonedb_system->index;
-+#else
-       *count = sizeof(timezonedb_idx_builtin) / sizeof(*timezonedb_idx_builtin);
-       return timezonedb_idx_builtin;
-+#endif
- }
+ const timelib_tzdb_index_entry *timelib_timezone_identifiers_list(timelib_tzdb *tzdb, int *count)
+@@ -433,7 +912,30 @@ const timelib_tzdb_index_entry *timelib_
  int timelib_timezone_id_is_valid(char *timezone, const timelib_tzdb *tzdb)
  {
        const unsigned char *tzf;
@@ -564,38 +571,34 @@ r1: initial revision
 +
 +              snprintf(fname, sizeof fname, ZONEINFO_PREFIX "/%s", canonical_tzname(timezone));
 +
-+              return stat(fname, &st) == 0 && is_valid_tzfile(&st);
++              return stat(fname, &st) == 0 && is_valid_tzfile(&st, 0);
 +      }
 +#endif
++
 +      return (inmem_seek_to_tz_position(&tzf, timezone, tzdb));
  }
  
- static void skip_64bit_preamble(const unsigned char **tzf, timelib_tzinfo *tz)
-@@ -374,24 +870,54 @@ static void read_64bit_header(const unsi
- timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb)
+ static int skip_64bit_preamble(const unsigned char **tzf, timelib_tzinfo *tz)
+@@ -475,12 +977,14 @@ static timelib_tzinfo* timelib_tzinfo_ct
+ timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb, int *error_code)
  {
        const unsigned char *tzf;
 +      char *memmap = NULL;
 +      size_t maplen;
        timelib_tzinfo *tmp;
        int version;
+       int transitions_result, types_result;
+       unsigned int type; /* TIMELIB_TZINFO_PHP or TIMELIB_TZINFO_ZONEINFO */
  
 -      if (seek_to_tz_position(&tzf, timezone, tzdb)) {
 +      if (seek_to_tz_position(&tzf, timezone, &memmap, &maplen, tzdb)) {
                tmp = timelib_tzinfo_ctor(timezone);
  
-               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);
+               version = read_preamble(&tzf, tmp, &type);
+@@ -503,6 +1007,29 @@ timelib_tzinfo *timelib_parse_tzfile(cha
+                       timelib_tzinfo_dtor(tmp);
+                       return NULL;
+               }
 +
 +#ifdef HAVE_SYSTEM_TZDATA
 +              if (memmap) {
@@ -605,43 +608,40 @@ 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;
 +                      }
 +                      else {
-+                              strcpy(tmp->location.country_code, "??");
-+                              tmp->bc = 0;
-+                              tmp->location.comments = strdup("");
++                              set_default_location_and_comments(&tzf, tmp);
 +                      }
 +
 +                      /* Now done with the mmap segment - discard it. */
 +                      munmap(memmap, maplen);
-+              } else
++              } else {
++#endif
+               if (version == 2 || version == 3) {
+                       if (!skip_64bit_preamble(&tzf, tmp)) {
+                               /* 64 bit preamble is not in place */
+@@ -520,6 +1047,9 @@ timelib_tzinfo *timelib_parse_tzfile(cha
+               } else {
+                       set_default_location_and_comments(&tzf, tmp);
+               }
++#ifdef HAVE_SYSTEM_TZDATA
++              }
 +#endif
-+              {
-+                      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);
-+                      }
-+                      /* PHP-style - use the embedded info. */
-+                      read_location(&tzf, tmp);
-+              }
        } else {
+               *error_code = TIMELIB_ERROR_NO_SUCH_TIMEZONE;
                tmp = NULL;
-       }
-diff -up php-5.6.9RC1/ext/date/lib/timelib.m4.systzdata php-5.6.9RC1/ext/date/lib/timelib.m4
---- php-5.6.9RC1/ext/date/lib/timelib.m4.systzdata     2015-04-30 00:00:18.000000000 +0200
-+++ php-5.6.9RC1/ext/date/lib/timelib.m4       2015-04-30 06:32:08.549500385 +0200
-@@ -78,3 +78,17 @@ stdlib.h
+diff -up ./ext/date/lib/timelib.m4.systzdata ./ext/date/lib/timelib.m4
+--- ./ext/date/lib/timelib.m4.systzdata        2017-08-22 09:40:38.000000000 +0200
++++ ./ext/date/lib/timelib.m4  2017-08-22 11:32:29.357799927 +0200
+@@ -81,3 +81,16 @@ io.h
  
  dnl Check for strtoll, atoll
- AC_CHECK_FUNCS(strtoll atoll strftime)
+ AC_CHECK_FUNCS(strtoll atoll strftime gettimeofday)
 +
 +PHP_ARG_WITH(system-tzdata, for use of system timezone data,
 +[  --with-system-tzdata[=DIR]      to specify use of system timezone data],
@@ -655,4 +655,3 @@ diff -up php-5.6.9RC1/ext/date/lib/timelib.m4.systzdata php-5.6.9RC1/ext/date/li
 +                         [Define for location of system timezone data])
 +   fi
 +fi
-+
This page took 0.04722 seconds and 4 git commands to generate.