diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6764d65 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,27 @@ +name: CI +on: + push: + branches: ['*'] +jobs: + test-linux: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + php-rel: ['8.2', '8.3', '8.4', '8.5'] + ts-state: [ts, nts] + + steps: + - uses: actions/checkout@v5 + - name: Setup PHP + id: setup-php + uses: shivammathur/setup-php@v2 + with: + php-version: '${{ matrix.php-rel }}' + env: + phpts: '${{ matrix.ts-state }}' + + - name: build extension + run: phpize && ./configure --enable-rar && make + - name: run tests + run: rm run-tests.php && cp run-tests8.php run-tests.php && make test diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 0000000..5102549 --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,49 @@ +name: Publish Windows Releases +on: + release: + types: [created] + push: + branches: ['*'] + +permissions: + contents: write + +jobs: + get-extension-matrix: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.extension-matrix.outputs.matrix }} + steps: + - name: Checkout + uses: actions/checkout@v5 + - name: Get the extension matrix + id: extension-matrix + uses: php/php-windows-builder/extension-matrix@v1 + build: + needs: get-extension-matrix + runs-on: ${{ matrix.os }} + continue-on-error: false + strategy: + fail-fast: true + matrix: ${{fromJson(needs.get-extension-matrix.outputs.matrix)}} + steps: + - name: Checkout + uses: actions/checkout@v5 + - name: Build the extension + uses: php/php-windows-builder/extension@v1 + with: + php-version: ${{ matrix.php-version }} + arch: ${{ matrix.arch }} + ts: ${{ matrix.ts }} + args: '--enable-rar' + test-runner: 'run-tests8.php' + release: + runs-on: ubuntu-latest + needs: build + if: ${{ github.event_name == 'release' }} + steps: + - name: Upload artifact to the release + uses: php/php-windows-builder/release@v1 + with: + release: ${{ github.event.release.tag_name }} +# token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 86886db..aea2440 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ /modules /missing /.deps +*.dep /.libs /Makefile /Makefile.fragments diff --git a/composer.json b/composer.json index 30795ef..af395a3 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { - "name": "rar", - "type": "extension", + "name": "php-win-ext/rar", + "type": "php-ext", "license": [ "PHP License" ], @@ -14,5 +14,8 @@ "email": "tony@daylessday.org" } ], + "require": { + "php": ">= 8.0.0" + }, "description": "rar extension" } \ No newline at end of file diff --git a/config.w32 b/config.w32 index b72a7c0..a61ec2a 100644 --- a/config.w32 +++ b/config.w32 @@ -31,7 +31,7 @@ if (PHP_RAR != "no") { arcread.cpp filefn.cpp \ global.cpp list.cpp \ encname.cpp file.cpp \ - secpassword.cpp options.cpp", "rar"); + secpassword.cpp options.cpp", "rar", "unrar_obj"); AC_DEFINE("HAVE_RAR", 1, "Rar support"); } diff --git a/php_rar.h b/php_rar.h index 9bdee06..3c0c4ce 100644 --- a/php_rar.h +++ b/php_rar.h @@ -51,7 +51,7 @@ extern zend_module_entry rar_module_entry; #define phpext_rar_ptr &rar_module_entry -#define PHP_RAR_VERSION "4.2.0" +#define PHP_RAR_VERSION "4.2.1" #ifdef PHP_WIN32 #define PHP_RAR_API __declspec(dllexport) diff --git a/rar_error.c b/rar_error.c index 13a742b..f9085ef 100644 --- a/rar_error.c +++ b/rar_error.c @@ -247,7 +247,7 @@ void minit_rarerror(TSRMLS_D) /* {{{ */ zend_exception_get_default(TSRMLS_C), NULL TSRMLS_CC); #else rarexception_ce_ptr = zend_register_internal_class_ex(&ce, - zend_exception_get_default(TSRMLS_C)); + zend_ce_exception); #endif rarexception_ce_ptr->ce_flags |= ZEND_ACC_FINAL; zend_declare_property_bool(rarexception_ce_ptr, "usingExceptions", diff --git a/rararch.c b/rararch.c index 7cbfa26..8a5ca6c 100644 --- a/rararch.c +++ b/rararch.c @@ -544,7 +544,8 @@ static int rararch_dimensions_preamble(rar_file_t *rar, /* }}} */ /* {{{ RarArchive count_elements handler */ -static int rararch_count_elements(handler_this_t *object, long *count TSRMLS_DC) + +static int rararch_count_elements(zend_object *object, zend_long *count TSRMLS_DC) { rar_file_t *rar = NULL; size_t entry_count; @@ -555,10 +556,10 @@ static int rararch_count_elements(handler_this_t *object, long *count TSRMLS_DC) } entry_count = _rar_entry_count(rar); - if (entry_count > LONG_MAX) - entry_count = (size_t) LONG_MAX; + if (entry_count > ZEND_LONG_MAX) + entry_count = ZEND_LONG_MAX; - *count = (long) entry_count; + *count = (zend_long) entry_count; return SUCCESS; } @@ -970,6 +971,13 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_rararchive_void, 0) ZEND_END_ARG_INFO() + +#if PHP_VERSION_ID >= 80200 +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rararchive_tostring, 0, 0, IS_STRING, 0) +ZEND_END_ARG_INFO() +#else +#define arginfo_rararchive_tostring arginfo_rararchive_void +#endif /* }}} */ static zend_function_entry php_rararch_class_functions[] = { @@ -984,7 +992,7 @@ static zend_function_entry php_rararch_class_functions[] = { PHP_ME_MAPPING(isBroken, rar_broken_is, arginfo_rararchive_void, ZEND_ACC_PUBLIC) PHP_ME_MAPPING(setAllowBroken, rar_allow_broken_set, arginfo_rararchive_setallowbroken, ZEND_ACC_PUBLIC) PHP_ME_MAPPING(close, rar_close, arginfo_rararchive_void, ZEND_ACC_PUBLIC) - PHP_ME(rararch, __toString, arginfo_rararchive_void, ZEND_ACC_PUBLIC) + PHP_ME(rararch, __toString, arginfo_rararchive_tostring, ZEND_ACC_PUBLIC) PHP_ME_MAPPING(__construct, rar_bogus_ctor, arginfo_rararchive_void, ZEND_ACC_PRIVATE | ZEND_ACC_CTOR) #if PHP_MAJOR_VERSION >= 8 PHP_ME(rararch, getIterator, arginfo_rararchive_getiterator, ZEND_ACC_PUBLIC) diff --git a/rarentry.c b/rarentry.c index 5e680f6..d5f6e7c 100644 --- a/rarentry.c +++ b/rarentry.c @@ -65,7 +65,11 @@ void _rar_entry_to_zval(zval *parent, char *filename; int filename_size, filename_len; +#if PHP_MAJOR_VERSION >= 7 + zend_long unp_size; /* zval stores PHP ints as zend_long, so use that here */ +#else long unp_size; /* zval stores PHP ints as long, so use that here */ +#endif zval *parent_copy = parent; #if PHP_MAJOR_VERSION < 7 /* allocate zval on the heap */ @@ -85,7 +89,9 @@ void _rar_entry_to_zval(zval *parent, zend_update_property(rar_class_entry_ptr, obj, "rarfile", sizeof("rararch") - 1, parent_copy TSRMLS_CC); -#if ULONG_MAX > 0xffffffffUL +#if PHP_MAJOR_VERSION >= 7 && ZEND_ENABLE_ZVAL_LONG64 + unp_size = ((zend_long) entry->UnpSize) + (((zend_long) entry->UnpSizeHigh) << 32); +#elif PHP_MAJOR_VERSION < 7 && ULONG_MAX > 0xffffffffUL unp_size = ((long) entry->UnpSize) + (((long) entry->UnpSizeHigh) << 32); #else /* for 32-bit long, at least don't give negative values */ @@ -735,6 +741,13 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_rar_void, 0) ZEND_END_ARG_INFO() + +#if PHP_VERSION_ID >= 80200 +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rar_tostring, 0, 0, IS_STRING, 0) +ZEND_END_ARG_INFO() +#else +#define arginfo_rar_tostring arginfo_rar_void +#endif /* }}} */ static zend_function_entry php_rar_class_functions[] = { @@ -755,7 +768,7 @@ static zend_function_entry php_rar_class_functions[] = { PHP_ME(rarentry, getRedirType, arginfo_rar_void, ZEND_ACC_PUBLIC) PHP_ME(rarentry, isRedirectToDirectory, arginfo_rar_void, ZEND_ACC_PUBLIC) PHP_ME(rarentry, getRedirTarget, arginfo_rar_void, ZEND_ACC_PUBLIC) - PHP_ME(rarentry, __toString, arginfo_rar_void, ZEND_ACC_PUBLIC) + PHP_ME(rarentry, __toString, arginfo_rar_tostring, ZEND_ACC_PUBLIC) PHP_ME_MAPPING(__construct, rar_bogus_ctor, arginfo_rar_void, ZEND_ACC_PRIVATE | ZEND_ACC_CTOR) {NULL, NULL, NULL} }; diff --git a/run-tests8.php b/run-tests8.php index 062dabb..ef11707 100644 --- a/run-tests8.php +++ b/run-tests8.php @@ -2829,10 +2829,10 @@ function run_test($php, $file, array $env) gdb --args {$cmd} ;; "valgrind") - USE_ZEND_ALLOC=0 valgrind $2 ${cmd} + USE_ZEND_ALLOC=0 valgrind $2 {$cmd} ;; "rr") - rr record $2 ${cmd} + rr record $2 {$cmd} ;; *) {$cmd} diff --git a/tests/002.phpt b/tests/002.phpt index 5c00904..b4970a7 100644 --- a/tests/002.phpt +++ b/tests/002.phpt @@ -163,5 +163,5 @@ array(2) { Warning: rar_open(): Failed to open %s: ERAR_EOPEN (file open error) in %s on line %d -Warning: rar_list() expects parameter 1 to be RarArchive, boo%s given in %s on line %d +Warning: rar_list() expects parameter 1 to be RarArchive, %s given in %s on line %d Done diff --git a/tests/003.phpt b/tests/003.phpt index 6d614a3..89c871a 100644 --- a/tests/003.phpt +++ b/tests/003.phpt @@ -91,5 +91,5 @@ object(RarEntry)#%d (%d) { Warning: rar_open(): Failed to open %s: ERAR_EOPEN (file open error) in %s on line %d -Warning: rar_entry_get() expects parameter 1 to be RarArchive, boo%s given in %s on line %d +Warning: rar_entry_get() expects parameter 1 to be RarArchive, %s given in %s on line %d Done diff --git a/tests/008.phpt b/tests/008.phpt index 1287f10..1b6c75c 100644 --- a/tests/008.phpt +++ b/tests/008.phpt @@ -31,6 +31,6 @@ bool(false) Warning: rar_open(): Failed to open %s: ERAR_EOPEN (file open error) in %s on line %d -Warning: rar_entry_get() expects parameter 1 to be RarArchive, boo%s given in %s on line %d +Warning: rar_entry_get() expects parameter 1 to be RarArchive, %s given in %s on line %d Done diff --git a/tests/011.phpt b/tests/011.phpt index d8ea913..aea2512 100644 --- a/tests/011.phpt +++ b/tests/011.phpt @@ -9,10 +9,6 @@ $rar_file1 = rar_open(dirname(__FILE__).'/multi.part1.rar'); $entries = rar_list($rar_file1); echo count($entries)." files:\n\n"; //var_dump($entries); -function int32_to_hex($value) { - $value &= 0xffffffff; - return str_pad(strtoupper(dechex($value)), 8, "0", STR_PAD_LEFT); -} foreach ($entries as $e) { $stream = $e->getStream(); if ($stream === false) { @@ -25,7 +21,7 @@ foreach ($entries as $e) { $a .= fread($stream, 8192); } echo strlen($a)." bytes, CRC "; - echo int32_to_hex(crc32($a))."\n\n"; //you can confirm they're equal to those given by $e->getCrc() + echo strtoupper(hash("crc32b", $a))."\n\n"; //you can confirm they're equal to those given by $e->getCrc() } echo "Done\n"; diff --git a/tests/019.phpt b/tests/019.phpt index c0c7323..b6b8cb6 100644 --- a/tests/019.phpt +++ b/tests/019.phpt @@ -9,10 +9,6 @@ $rar_file1 = rar_open(dirname(__FILE__).'/store_method.rar'); $entries = rar_list($rar_file1); echo count($entries)." files:\n\n"; //var_dump($entries); -function int32_to_hex($value) { - $value &= 0xffffffff; - return str_pad(strtoupper(dechex($value)), 8, "0", STR_PAD_LEFT); -} foreach ($entries as $e) { $stream = $e->getStream(); echo $e->getName().": "; @@ -21,7 +17,7 @@ foreach ($entries as $e) { $a .= fread($stream, 512); } echo strlen($a)." bytes, CRC "; - echo int32_to_hex(crc32($a))."\n\n"; //you can confirm they're equal to those given by $e->getCrc() + echo strtoupper(hash("crc32b", $a))."\n\n"; //you can confirm they're equal to those given by $e->getCrc() } echo "Done\n"; diff --git a/tests/020.phpt b/tests/020.phpt index 111f667..37df3f0 100644 --- a/tests/020.phpt +++ b/tests/020.phpt @@ -9,10 +9,6 @@ $rar_file1 = rar_open(dirname(__FILE__).'/solid.rar'); $entries = rar_list($rar_file1); echo count($entries)." files:\n\n"; //var_dump($entries); -function int32_to_hex($value) { - $value &= 0xffffffff; - return str_pad(strtoupper(dechex($value)), 8, "0", STR_PAD_LEFT); -} foreach ($entries as $e) { $stream = $e->getStream(); echo $e->getName().": "; @@ -21,7 +17,7 @@ foreach ($entries as $e) { $a .= fread($stream, 8192); } echo strlen($a)." bytes, CRC "; - echo int32_to_hex(crc32($a))."\n\n"; //you can confirm they're equal to those given by $e->getCrc() + echo strtoupper(hash("crc32b", $a))."\n\n"; //you can confirm they're equal to those given by $e->getCrc() } echo "Done\n"; diff --git a/tests/038.phpt b/tests/038.phpt index 7f06547..bcc6b5b 100644 --- a/tests/038.phpt +++ b/tests/038.phpt @@ -4,6 +4,9 @@ RarArchive get iterator on closed file --FILE-- =80500){ + ini_set('fatal_error_backtraces', 'Off'); +} $rarF = RarArchive::open(dirname(__FILE__) . '/latest_winrar.rar'); $rarF->close(); foreach ($rarF as $k => $rarE) { diff --git a/tests/046.phpt b/tests/046.phpt index c93b64c..7f4c19d 100644 --- a/tests/046.phpt +++ b/tests/046.phpt @@ -10,10 +10,6 @@ function resolve($vol) { else return null; } -function int32_to_hex($value) { - $value &= 0xffffffff; - return str_pad(strtoupper(dechex($value)), 8, "0", STR_PAD_LEFT); -} $rar_file1 = rar_open(dirname(__FILE__).'/multi_broken.part1.rar', null, 'resolve'); foreach ($rar_file1 as $e) { $stream = $e->getStream(); @@ -23,7 +19,7 @@ foreach ($rar_file1 as $e) { $a .= fread($stream, 8192); } echo strlen($a)." bytes, CRC "; - echo int32_to_hex(crc32($a))."\n\n"; //you can confirm they're equal to those given by $e->getCrc() + echo strtoupper(hash("crc32b", $a))."\n\n"; //you can confirm they're equal to those given by $e->getCrc() } echo "Done\n"; diff --git a/tests/047.phpt b/tests/047.phpt index 8bd3e90..e0a5c24 100644 --- a/tests/047.phpt +++ b/tests/047.phpt @@ -10,10 +10,6 @@ function resolve($vol) { else return null; } -function int32_to_hex($value) { - $value &= 0xffffffff; - return str_pad(strtoupper(dechex($value)), 8, "0", STR_PAD_LEFT); -} echo "Fail:\n"; $rar_file1 = rar_open(dirname(__FILE__).'/multi_broken.part1.rar'); $entry = $rar_file1->getEntry('file2.txt'); @@ -22,7 +18,7 @@ echo "\nSuccess:\n"; $rar_file1 = rar_open(dirname(__FILE__).'/multi_broken.part1.rar', null, 'resolve'); $entry = $rar_file1->getEntry('file2.txt'); $entry->extract(null, dirname(__FILE__) . "/temp_file2.txt"); -echo int32_to_hex(crc32(file_get_contents(dirname(__FILE__) . "/temp_file2.txt"))); +echo strtoupper(hash("crc32b", file_get_contents(dirname(__FILE__) . "/temp_file2.txt"))); echo "\n"; echo "Done\n"; ?> diff --git a/tests/055.phpt b/tests/055.phpt index 73d36f0..2d981d9 100644 --- a/tests/055.phpt +++ b/tests/055.phpt @@ -11,17 +11,13 @@ function resolve($vol) { else return null; } -function int32_to_hex($value) { - $value &= 0xffffffff; - return str_pad(strtoupper(dechex($value)), 8, "0", STR_PAD_LEFT); -} $stream = fopen("rar://" . dirname(__FILE__) . '/multi_broken.part1.rar' . "#file2.txt", "r", false, stream_context_create(array('rar'=>array('volume_callback'=>'resolve')))); $a = stream_get_contents($stream); echo strlen($a)." bytes, CRC "; -echo int32_to_hex(crc32($a))."\n\n"; //you can confirm they're equal to those given by $e->getCrc() +echo strtoupper(hash("crc32b", $a))."\n\n"; //you can confirm they're equal to those given by $e->getCrc() echo "Done.\n"; --EXPECTF-- 17704 bytes, CRC F2C79881 diff --git a/tests/086.phpt b/tests/086.phpt index 0c3b03b..58f19d0 100644 --- a/tests/086.phpt +++ b/tests/086.phpt @@ -7,6 +7,9 @@ if (key_exists('USE_ZEND_ALLOC', $_ENV) && PHP_VERSION_ID < 70000) die('skip do ?> --FILE-- =80500){ + ini_set('fatal_error_backtraces', 'Off'); +} $f1 = dirname(__FILE__) . "/latest_winrar.rar"; $a = RarArchive::open($f1); diff --git a/tests/087.phpt b/tests/087.phpt index 3b2c48f..fedc024 100644 --- a/tests/087.phpt +++ b/tests/087.phpt @@ -4,6 +4,9 @@ RarArchive read_property gives a fatal error on a write context --FILE-- =80500){ + ini_set('fatal_error_backtraces', 'Off'); +} $f1 = dirname(__FILE__) . "/latest_winrar.rar"; $a = RarArchive::open($f1); diff --git a/tests/088.phpt b/tests/088.phpt index b637e09..4d62663 100644 --- a/tests/088.phpt +++ b/tests/088.phpt @@ -7,6 +7,9 @@ if (key_exists('USE_ZEND_ALLOC', $_ENV) && PHP_VERSION_ID < 70000) die('skip do ?> --FILE-- =80500){ + ini_set('fatal_error_backtraces', 'Off'); +} $f1 = dirname(__FILE__) . "/latest_winrar.rar"; $a = RarArchive::open($f1); diff --git a/tests/089.phpt b/tests/089.phpt index 3f57615..6fcb868 100644 --- a/tests/089.phpt +++ b/tests/089.phpt @@ -4,6 +4,9 @@ RarArchive unset_property gives a fatal error --FILE-- =80500){ + ini_set('fatal_error_backtraces', 'Off'); +} $f1 = dirname(__FILE__) . "/latest_winrar.rar"; $a = RarArchive::open($f1); diff --git a/tests/093.phpt b/tests/093.phpt index e3b5da2..93fb095 100644 --- a/tests/093.phpt +++ b/tests/093.phpt @@ -4,6 +4,9 @@ Traversal of RarArchive with foreach by reference gives error --FILE-- =80500){ + ini_set('fatal_error_backtraces', 'Off'); +} $f1 = dirname(__FILE__) . "/latest_winrar.rar"; $a = RarArchive::open($f1); diff --git a/tests/101.phpt b/tests/101.phpt index 4d372b6..ebbf01c 100644 --- a/tests/101.phpt +++ b/tests/101.phpt @@ -3,6 +3,7 @@ Supports version 5 RAR files --SKIPIF--