From 835882713ecf97fe548361e90fbe0f50bd6c7c7f Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 4 Aug 2020 10:57:36 +0200 Subject: [PATCH 1/9] Add alpine based docker file --- azure-pipelines.yml | 81 +----------------------------------------- azure/Dockerfile | 84 ++++++++++++++++++++++++++++++++++++++++++++ azure/alpine_job.yml | 6 ++++ 3 files changed, 91 insertions(+), 80 deletions(-) create mode 100644 azure/Dockerfile create mode 100644 azure/alpine_job.yml diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 20198f888be42..a3e71c9bee3fc 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -12,83 +12,4 @@ trigger: - UPGRADING.INTERNALS jobs: - - template: azure/job.yml - parameters: - configurationName: DEBUG_NTS - configurationParameters: '--enable-debug --disable-zts' - - template: azure/job.yml - parameters: - configurationName: RELEASE_ZTS - configurationParameters: '--disable-debug --enable-zts' - - template: azure/i386/job.yml - parameters: - configurationName: I386_DEBUG_ZTS - configurationParameters: '--enable-debug --enable-zts' - - template: azure/macos/job.yml - parameters: - configurationName: MACOS_DEBUG_NTS - configurationParameters: '--enable-debug --disable-zts' - - ${{ if eq(variables['Build.Reason'], 'Schedule') }}: - - template: azure/job.yml - parameters: - configurationName: DEBUG_ZTS - configurationParameters: '--enable-debug --enable-zts' - - template: azure/job.yml - parameters: - configurationName: RELEASE_NTS - configurationParameters: '--disable-debug --disable-zts' - - template: azure/i386/job.yml - parameters: - configurationName: I386_DEBUG_NTS - configurationParameters: '--enable-debug --disable-zts' - - template: azure/i386/job.yml - parameters: - configurationName: I386_RELEASE_NTS - configurationParameters: '--disable-debug --disable-zts' - - template: azure/i386/job.yml - parameters: - configurationName: I386_RELEASE_ZTS - configurationParameters: '--disable-debug --enable-zts' - - template: azure/macos/job.yml - parameters: - configurationName: MACOS_DEBUG_ZTS - configurationParameters: '--enable-debug --enable-zts' - - template: azure/macos/job.yml - parameters: - configurationName: MACOS_RELEASE_NTS - configurationParameters: '--disable-debug --disable-zts' - - template: azure/macos/job.yml - parameters: - configurationName: MACOS_RELEASE_ZTS - configurationParameters: '--disable-debug --enable-zts' - - template: azure/job.yml - parameters: - configurationName: DEBUG_ZTS_ASAN_UBSAN - configurationParameters: >- - --enable-debug --enable-zts - CFLAGS='-fsanitize=undefined,address -DZEND_TRACK_ARENA_ALLOC' - LDFLAGS='-fsanitize=undefined,address' - runTestsParameters: --asan - timeoutInMinutes: 310 - - template: azure/msan_job.yml - parameters: - configurationName: DEBUG_ZTS_MSAN - configurationParameters: '--enable-debug --enable-zts' - runTestsParameters: --asan - timeoutInMinutes: 90 - - template: azure/community_job.yml - parameters: - configurationName: COMMUNITY - configurationParameters: >- - --enable-debug --enable-zts - CFLAGS='-fsanitize=undefined,address -fno-sanitize-recover -DZEND_TRACK_ARENA_ALLOC' - LDFLAGS='-fsanitize=undefined,address' - - template: azure/coverage_job.yml - parameters: - configurationName: COVERAGE_DEBUG_ZTS - configurationParameters: '--enable-debug --disable-zts' - timeoutInMinutes: 90 - - template: azure/file_cache_job.yml - parameters: - configurationName: DEBUG_NTS_FILE_CACHE - configurationParameters: '--enable-debug --disable-zts' + - template: azure/alpine_job.yml diff --git a/azure/Dockerfile b/azure/Dockerfile new file mode 100644 index 0000000000000..d1bf9dc688df7 --- /dev/null +++ b/azure/Dockerfile @@ -0,0 +1,84 @@ +FROM alpine:3.12 + +RUN apk add \ + aspell-dev \ + autoconf \ + bison \ + bzip2-dev \ + curl-dev \ + freetype-dev \ + g++ \ + gcc \ + gettext-dev \ + gnu-libiconv-dev \ + gmp-dev \ + icu-dev \ + jpeg-dev \ + libffi-dev \ + libpng-dev \ + libsodium-dev \ + libwebp-dev \ + libxml2-dev \ + libxpm-dev \ + libxslt-dev \ + libzip-dev \ + make \ + oniguruma-dev \ + openssl-dev \ + pkgconf \ + re2c \ + readline-dev \ + sqlite-dev \ + tidyhtml-dev + +ENV SKIP_IO_CAPTURE_TESTS=1 + +WORKDIR /php-src +COPY . /php-src + +RUN ./buildconf +RUN ./configure \ + --enable-option-checking=fatal \ + --enable-debug \ + --enable-werror \ + --enable-phpdbg \ + --enable-fpm \ + --enable-bcmath \ + --enable-calendar \ + --enable-dba \ + --enable-intl \ + --enable-exif \ + --enable-ftp \ + --enable-gd \ + --enable-mbstring \ + --enable-pcntl \ + --enable-shmop \ + --enable-soap \ + --enable-sockets \ + --enable-sysvmsg \ + --enable-sysvsem \ + --enable-sysvshm \ + --enable-xmlreader \ + --enable-zend-test \ + --with-curl \ + --with-bz2 \ + --with-iconv=/usr \ + --with-jpeg \ + --with-ffi \ + --with-freetype \ + --with-gettext \ + --with-gmp \ + --with-openssl \ + --with-pspell \ + --with-readline \ + --with-sodium \ + --with-tidy \ + --with-webp \ + --with-xpm \ + --with-xsl \ + --with-zip \ + --with-zlib + +RUN make clean && make -j`nproc` +RUN sapi/cli/php run-tests.php -j`nproc` -q \ + --show-diff -g FAIL,XFAIL,BORK,WARN,LEAK,XLEAK,SKIP diff --git a/azure/alpine_job.yml b/azure/alpine_job.yml new file mode 100644 index 0000000000000..b4429c46ac170 --- /dev/null +++ b/azure/alpine_job.yml @@ -0,0 +1,6 @@ +jobs: + - job: ALPINE + pool: + vmImage: 'ubuntu-20.04' + steps: + - script: docker build -f azure/Dockerfile . From 2e66c35e78f3928506af2db0f657266dbb156ccb Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 4 Aug 2020 12:50:55 +0200 Subject: [PATCH 2/9] Detect broken setlocale on musl --- ext/standard/config.m4 | 18 ++++++++++++++++++ ext/standard/string.c | 9 +++++++++ 2 files changed, 27 insertions(+) diff --git a/ext/standard/config.m4 b/ext/standard/config.m4 index 04b9d0aea1d6a..feab3915b7a71 100644 --- a/ext/standard/config.m4 +++ b/ext/standard/config.m4 @@ -368,6 +368,24 @@ if test "$ac_cv_strptime_decl_fails" = "yes"; then AC_DEFINE([HAVE_STRPTIME_DECL_FAILS], 1, [whether strptime() declaration fails]) fi +dnl musl has a badly broken setlocale() implementation that always reports success. +AC_CACHE_CHECK([whether setlocale() is broken], ac_cv_setlocale_broken, [ +AC_RUN_IFELSE([AC_LANG_SOURCE([[ +#include +int main() { + return setlocale(LC_CTYPE, "This locale certainly does not exist") == NULL; +} +]])],[ + ac_cv_setlocale_broken=yes +],[ + ac_cv_setlocale_broken=no +],[ + ac_cv_setlocale_broken=no +])]) +if test "$ac_cv_setlocale_broken" = "yes"; then + AC_DEFINE([HAVE_BROKEN_SETLOCALE], 1, [whether setlocale() is broken]) +fi + dnl dnl Check for arc4random on BSD systems dnl diff --git a/ext/standard/string.c b/ext/standard/string.c index 9a877ce13871a..5ed64912767c6 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -4662,6 +4662,15 @@ PHP_FUNCTION(setlocale) # ifndef PHP_WIN32 retval = php_my_setlocale(cat, loc ? ZSTR_VAL(loc) : NULL); +# if HAVE_BROKEN_SETLOCALE + /* musl libc always reports success for setlocale(). + * Manually whitelist the allowed locales "", "C" and "C.UTF-8" instead. */ + if (retval && loc && ZSTR_LEN(loc) != 0 + && !zend_string_equals_literal(loc, "C") + && !zend_string_equals_literal(loc, "C.UTF-8")) { + retval = NULL; + } +# endif # else if (loc) { /* BC: don't try /^[a-z]{2}_[A-Z]{2}($|\..*)/ except for /^u[ks]_U[KS]$/ */ From 8703d34269d34f60709cd6b4cdfd7d92615b2e9a Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 5 Aug 2020 20:07:03 +0200 Subject: [PATCH 3/9] Install tzdata --- azure/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/azure/Dockerfile b/azure/Dockerfile index d1bf9dc688df7..3d77bad82ae9b 100644 --- a/azure/Dockerfile +++ b/azure/Dockerfile @@ -29,7 +29,8 @@ RUN apk add \ re2c \ readline-dev \ sqlite-dev \ - tidyhtml-dev + tidyhtml-dev \ + tzdata ENV SKIP_IO_CAPTURE_TESTS=1 From 7005d994fd08f15680b4b2c0ac4f2c74f37fe475 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 12 Aug 2020 15:59:19 +0200 Subject: [PATCH 4/9] Explicitly expand strftime %Z --- ext/date/php_date.c | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index d81bc1659a990..ac28ef0fcdac9 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -1158,6 +1158,38 @@ PHP_FUNCTION(checkdate) } /* }}} */ +/* Explicitly expand stftime %Z format, to make it independent of the TZ environment + * variable and avoid libc behavior discrepancies. */ +zend_string *strftime_expand_tzname(zend_string *format, const char *tm_zone) +{ + size_t tm_zone_len = strlen(tm_zone); + zend_string_addref(format); + for (size_t i = 0; i < ZSTR_LEN(format);) { + if (ZSTR_VAL(format)[i] != '%') { + i++; + continue; + } + + if (ZSTR_VAL(format)[i+1] != 'Z') { + i += 2; + continue; + } + + zend_string *new_format = zend_string_concat3( + /* Format string up to %Z */ + ZSTR_VAL(format), i, + /* The timezone name */ + tm_zone, tm_zone_len, + /* Format string after %Z */ + ZSTR_VAL(format) + i + 2, ZSTR_LEN(format) - (i + 2) + ); + zend_string_release(format); + format = new_format; + i += tm_zone_len; + } + return format; +} + /* {{{ php_strftime - (gm)strftime helper */ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt) { @@ -1171,6 +1203,7 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt) timelib_tzinfo *tzi; timelib_time_offset *offset = NULL; zend_string *buf; + const char *tm_zone; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STR(format) @@ -1205,24 +1238,25 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt) ta.tm_wday = timelib_day_of_week(ts->y, ts->m, ts->d); ta.tm_yday = timelib_day_of_year(ts->y, ts->m, ts->d); if (gmt) { + tm_zone = "GMT"; ta.tm_isdst = 0; #if HAVE_STRUCT_TM_TM_GMTOFF ta.tm_gmtoff = 0; -#endif -#if HAVE_STRUCT_TM_TM_ZONE - ta.tm_zone = "GMT"; #endif } else { offset = timelib_get_time_zone_info(timestamp, tzi); + tm_zone = offset->abbr; ta.tm_isdst = offset->is_dst; #if HAVE_STRUCT_TM_TM_GMTOFF ta.tm_gmtoff = offset->offset; #endif + } #if HAVE_STRUCT_TM_TM_ZONE - ta.tm_zone = offset->abbr; + ta.tm_zone = tm_zone; #endif - } + + format = strftime_expand_tzname(format, tm_zone); /* VS2012 crt has a bug where strftime crash with %z and %Z format when the initial buffer is too small. See @@ -1243,6 +1277,7 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt) } #endif + zend_string_release(format); timelib_time_dtor(ts); if (!gmt) { timelib_time_offset_dtor(offset); From d1553c7ed3e49e348390a491aae859e1071057a6 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 12 Aug 2020 16:56:47 +0200 Subject: [PATCH 5/9] Revert "Explicitly expand strftime %Z" This reverts commit 7005d994fd08f15680b4b2c0ac4f2c74f37fe475. --- ext/date/php_date.c | 45 +++++---------------------------------------- 1 file changed, 5 insertions(+), 40 deletions(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index ac28ef0fcdac9..d81bc1659a990 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -1158,38 +1158,6 @@ PHP_FUNCTION(checkdate) } /* }}} */ -/* Explicitly expand stftime %Z format, to make it independent of the TZ environment - * variable and avoid libc behavior discrepancies. */ -zend_string *strftime_expand_tzname(zend_string *format, const char *tm_zone) -{ - size_t tm_zone_len = strlen(tm_zone); - zend_string_addref(format); - for (size_t i = 0; i < ZSTR_LEN(format);) { - if (ZSTR_VAL(format)[i] != '%') { - i++; - continue; - } - - if (ZSTR_VAL(format)[i+1] != 'Z') { - i += 2; - continue; - } - - zend_string *new_format = zend_string_concat3( - /* Format string up to %Z */ - ZSTR_VAL(format), i, - /* The timezone name */ - tm_zone, tm_zone_len, - /* Format string after %Z */ - ZSTR_VAL(format) + i + 2, ZSTR_LEN(format) - (i + 2) - ); - zend_string_release(format); - format = new_format; - i += tm_zone_len; - } - return format; -} - /* {{{ php_strftime - (gm)strftime helper */ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt) { @@ -1203,7 +1171,6 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt) timelib_tzinfo *tzi; timelib_time_offset *offset = NULL; zend_string *buf; - const char *tm_zone; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STR(format) @@ -1238,25 +1205,24 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt) ta.tm_wday = timelib_day_of_week(ts->y, ts->m, ts->d); ta.tm_yday = timelib_day_of_year(ts->y, ts->m, ts->d); if (gmt) { - tm_zone = "GMT"; ta.tm_isdst = 0; #if HAVE_STRUCT_TM_TM_GMTOFF ta.tm_gmtoff = 0; +#endif +#if HAVE_STRUCT_TM_TM_ZONE + ta.tm_zone = "GMT"; #endif } else { offset = timelib_get_time_zone_info(timestamp, tzi); - tm_zone = offset->abbr; ta.tm_isdst = offset->is_dst; #if HAVE_STRUCT_TM_TM_GMTOFF ta.tm_gmtoff = offset->offset; #endif - } #if HAVE_STRUCT_TM_TM_ZONE - ta.tm_zone = tm_zone; + ta.tm_zone = offset->abbr; #endif - - format = strftime_expand_tzname(format, tm_zone); + } /* VS2012 crt has a bug where strftime crash with %z and %Z format when the initial buffer is too small. See @@ -1277,7 +1243,6 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt) } #endif - zend_string_release(format); timelib_time_dtor(ts); if (!gmt) { timelib_time_offset_dtor(offset); From b0bee80463e79f994e56c1654a9ec3db20466b08 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 12 Aug 2020 16:56:52 +0200 Subject: [PATCH 6/9] Revert "Detect broken setlocale on musl" This reverts commit 2e66c35e78f3928506af2db0f657266dbb156ccb. --- ext/standard/config.m4 | 18 ------------------ ext/standard/string.c | 9 --------- 2 files changed, 27 deletions(-) diff --git a/ext/standard/config.m4 b/ext/standard/config.m4 index feab3915b7a71..04b9d0aea1d6a 100644 --- a/ext/standard/config.m4 +++ b/ext/standard/config.m4 @@ -368,24 +368,6 @@ if test "$ac_cv_strptime_decl_fails" = "yes"; then AC_DEFINE([HAVE_STRPTIME_DECL_FAILS], 1, [whether strptime() declaration fails]) fi -dnl musl has a badly broken setlocale() implementation that always reports success. -AC_CACHE_CHECK([whether setlocale() is broken], ac_cv_setlocale_broken, [ -AC_RUN_IFELSE([AC_LANG_SOURCE([[ -#include -int main() { - return setlocale(LC_CTYPE, "This locale certainly does not exist") == NULL; -} -]])],[ - ac_cv_setlocale_broken=yes -],[ - ac_cv_setlocale_broken=no -],[ - ac_cv_setlocale_broken=no -])]) -if test "$ac_cv_setlocale_broken" = "yes"; then - AC_DEFINE([HAVE_BROKEN_SETLOCALE], 1, [whether setlocale() is broken]) -fi - dnl dnl Check for arc4random on BSD systems dnl diff --git a/ext/standard/string.c b/ext/standard/string.c index 5ed64912767c6..9a877ce13871a 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -4662,15 +4662,6 @@ PHP_FUNCTION(setlocale) # ifndef PHP_WIN32 retval = php_my_setlocale(cat, loc ? ZSTR_VAL(loc) : NULL); -# if HAVE_BROKEN_SETLOCALE - /* musl libc always reports success for setlocale(). - * Manually whitelist the allowed locales "", "C" and "C.UTF-8" instead. */ - if (retval && loc && ZSTR_LEN(loc) != 0 - && !zend_string_equals_literal(loc, "C") - && !zend_string_equals_literal(loc, "C.UTF-8")) { - retval = NULL; - } -# endif # else if (loc) { /* BC: don't try /^[a-z]{2}_[A-Z]{2}($|\..*)/ except for /^u[ks]_U[KS]$/ */ From 6eafc6c3820215021ca1f914585ba9c07daaab90 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 12 Aug 2020 17:01:51 +0200 Subject: [PATCH 7/9] Add skipif for broken strftime %Z %Z does not work on musl libc. We have decided not work around this using manual expansion because people shouldn't be using strftime anyway. This function is slated for future deprecation. --- ext/date/tests/bug27780.phpt | 2 +- ext/date/tests/bug32555.phpt | 1 + ext/date/tests/bug33532.phpt | 1 + ext/standard/tests/time/strptime_basic.phpt | 9 +++++---- ext/standard/tests/time/strptime_parts.phpt | 7 ++++--- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ext/date/tests/bug27780.phpt b/ext/date/tests/bug27780.phpt index f6f21e4185129..331c90c5fff11 100644 --- a/ext/date/tests/bug27780.phpt +++ b/ext/date/tests/bug27780.phpt @@ -35,7 +35,7 @@ foreach ($timezones as $timezone) { foreach ($timestrings as $timestring) { $time = strtotime($timestring); - echo $time, strftime(" [%Y-%m-%d %H:%M:%S %Z]", $time), " [$timestring]\n"; + echo $time, date(" [Y-m-d H:i:s T]", $time), " [$timestring]\n"; } echo "\n"; diff --git a/ext/date/tests/bug32555.phpt b/ext/date/tests/bug32555.phpt index 03ed09fab49c3..9fcbd8261734a 100644 --- a/ext/date/tests/bug32555.phpt +++ b/ext/date/tests/bug32555.phpt @@ -3,6 +3,7 @@ Bug #32555 (strtotime("tomorrow") can return false) --SKIPIF-- --INI-- date.timezone=US/Eastern diff --git a/ext/date/tests/bug33532.phpt b/ext/date/tests/bug33532.phpt index 5323e8c8db18e..80b87f7e6d87d 100644 --- a/ext/date/tests/bug33532.phpt +++ b/ext/date/tests/bug33532.phpt @@ -6,6 +6,7 @@ date.timezone=UTC --SKIPIF-- --FILE-- --FILE-- --FILE-- Date: Wed, 12 Aug 2020 17:06:02 +0200 Subject: [PATCH 8/9] Don't test invalid strftime format The behavior in this case depends on the implementation. --- ext/date/tests/009.phpt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ext/date/tests/009.phpt b/ext/date/tests/009.phpt index 9d77a552ccfc0..624b2d5f66d7d 100644 --- a/ext/date/tests/009.phpt +++ b/ext/date/tests/009.phpt @@ -13,13 +13,11 @@ $t = mktime(0,0,0, 6, 27, 2006); var_dump(strftime("")); var_dump(strftime("%a %A %b %B %c %C %d %D %e %g %G %h %H %I %j %m %M %n %p %r %R %S %t %T %u %U %V %W %w %x %X %y %Y %Z %z %%", $t)); var_dump(strftime("%%q %%a", $t)); -var_dump(strftime("%q", $t)); var_dump(strftime("blah", $t)); var_dump(gmstrftime("")); var_dump(gmstrftime("%a %A %b %B %c %C %d %D %e %g %G %h %H %I %j %m %M %n %p %r %R %S %t %T %u %U %V %W %w %x %X %y %Y %Z %z %%", $t)); var_dump(gmstrftime("%%q %%a", $t)); -var_dump(gmstrftime("%q", $t)); var_dump(gmstrftime("blah", $t)); echo "Done\n"; @@ -29,12 +27,10 @@ bool(false) string(%d) "Tue Tuesday Jun June Tue Jun 27 00:00:00 2006 %s %s %" string(5) "%q %a" -string(%d) "%s" string(4) "blah" bool(false) string(%d) "Mon Monday Jun June Mon Jun 26 21:00:00 2006 %s %s %" string(5) "%q %a" -string(%d) "%s" string(4) "blah" Done From c940a60915f2937d26cf14f904b5476b860b9ee7 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 12 Aug 2020 17:24:30 +0200 Subject: [PATCH 9/9] Make setlocale skipifs musl-compatible --- ext/standard/tests/strings/setlocale_skipif.inc | 10 ++++++++++ ext/standard/tests/strings/setlocale_variation1.phpt | 5 ++--- ext/standard/tests/strings/setlocale_variation3.phpt | 5 ++--- ext/standard/tests/strings/strtoupper.phpt | 5 ++--- 4 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 ext/standard/tests/strings/setlocale_skipif.inc diff --git a/ext/standard/tests/strings/setlocale_skipif.inc b/ext/standard/tests/strings/setlocale_skipif.inc new file mode 100644 index 0000000000000..423dac3bfea0b --- /dev/null +++ b/ext/standard/tests/strings/setlocale_skipif.inc @@ -0,0 +1,10 @@ + --FILE-- --FILE-- --FILE--