Skip to content
Merged
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
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -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 }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/modules
/missing
/.deps
*.dep
/.libs
/Makefile
/Makefile.fragments
Expand Down
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rar",
"type": "extension",
"name": "php-win-ext/rar",
"type": "php-ext",
"license": [
"PHP License"
],
Expand All @@ -14,5 +14,8 @@
"email": "tony@daylessday.org"
}
],
"require": {
"php": ">= 8.0.0"
},
"description": "rar extension"
}
2 changes: 1 addition & 1 deletion config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
2 changes: 1 addition & 1 deletion php_rar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion rar_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 13 additions & 5 deletions rararch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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[] = {
Expand All @@ -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)
Expand Down
17 changes: 15 additions & 2 deletions rarentry.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 */
Expand Down Expand Up @@ -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[] = {
Expand All @@ -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}
};
Expand Down
4 changes: 2 additions & 2 deletions run-tests8.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion tests/002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/008.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 1 addition & 5 deletions tests/011.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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";
Expand Down
6 changes: 1 addition & 5 deletions tests/019.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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().": ";
Expand All @@ -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";
Expand Down
6 changes: 1 addition & 5 deletions tests/020.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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().": ";
Expand All @@ -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";
Expand Down
3 changes: 3 additions & 0 deletions tests/038.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ RarArchive get iterator on closed file
<?php if(!extension_loaded("rar")) print "skip"; ?>
--FILE--
<?php
if (PHP_VERSION_ID>=80500){
ini_set('fatal_error_backtraces', 'Off');
}
$rarF = RarArchive::open(dirname(__FILE__) . '/latest_winrar.rar');
$rarF->close();
foreach ($rarF as $k => $rarE) {
Expand Down
6 changes: 1 addition & 5 deletions tests/046.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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";
Expand Down
6 changes: 1 addition & 5 deletions tests/047.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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";
?>
Expand Down
6 changes: 1 addition & 5 deletions tests/055.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/086.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ if (key_exists('USE_ZEND_ALLOC', $_ENV) && PHP_VERSION_ID < 70000) die('skip do
?>
--FILE--
<?php
if (PHP_VERSION_ID>=80500){
ini_set('fatal_error_backtraces', 'Off');
}

$f1 = dirname(__FILE__) . "/latest_winrar.rar";
$a = RarArchive::open($f1);
Expand Down
Loading