Skip to content

Commit

Permalink
- Omitted volume not found warning if volume callback was specified.
Browse files Browse the repository at this point in the history
. rar_broken_is omits no warnings (except the volume not found one, but see above)
- Tests for reading broken files
- Other tests for rararch.c

git-svn-id: http://svn.php.net/repository/pecl/rar/trunk@300083 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
cataphract committed Jun 2, 2010
1 parent 438d8a4 commit 9d49ce4
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 77 deletions.
1 change: 0 additions & 1 deletion php_rar.h
Expand Up @@ -43,7 +43,6 @@
/* TODO: test url_stater/dir_opener cache exaustion */
/* TODO: optimize _rar_nav_directory_match with the depth */
/* TODO: tests with truncated RAR archive (for which _rar_list_files fails) */
/* TODO: tests for allow broken RAR */

#ifndef PHP_RAR_H
#define PHP_RAR_H
Expand Down
5 changes: 3 additions & 2 deletions rar.c
Expand Up @@ -347,7 +347,7 @@ int CALLBACK _rar_unrar_callback(UINT msg, LPARAM UserData, LPARAM P1, LPARAM P2
}
else if (msg == UCM_CHANGEVOLUME) {
if (((int) P2) == RAR_VOL_ASK) {
int ret;
int ret, called_cb = 0;
if (userdata->callable == NULL) {
/* if there's no callback, abort */
ret = -1;
Expand All @@ -360,6 +360,7 @@ int CALLBACK _rar_unrar_callback(UINT msg, LPARAM UserData, LPARAM P1, LPARAM P2
TSRMLS_CC) == SUCCESS) {
ret = _rar_unrar_volume_user_callback(
(char*) P1, &fci, &cache TSRMLS_CC);
called_cb = 1;
}
else {
ret = -1;
Expand All @@ -368,7 +369,7 @@ int CALLBACK _rar_unrar_callback(UINT msg, LPARAM UserData, LPARAM P1, LPARAM P2
}

/* always a warning, never an exception here */
if (ret == -1)
if (ret == -1 && !called_cb)
php_error_docref(NULL TSRMLS_CC, E_WARNING,
"Volume %s was not found", (char*) P1);

Expand Down
15 changes: 8 additions & 7 deletions rararch.c
Expand Up @@ -484,11 +484,8 @@ static int rararch_has_dimension(zval *object, zval *offset, int check_empty TSR
return 0;
}

if (rararch_dimensions_preamble(rar, offset, &index, 1 TSRMLS_CC) ==
FAILURE)
return 0;

return 1;
return (rararch_dimensions_preamble(rar, offset, &index, 1 TSRMLS_CC) ==
SUCCESS);
}
/* }}} */

Expand Down Expand Up @@ -688,15 +685,19 @@ PHP_FUNCTION(rar_broken_is)
{
zval *file = getThis();
rar_file_t *rar = NULL;
int result;
int result,
orig_allow_broken;

RAR_THIS_OR_NO_ARGS(file);

if (_rar_get_file_resource(file, &rar TSRMLS_CC) == FAILURE) {
RETURN_FALSE;
}

orig_allow_broken = rar->allow_broken;
rar->allow_broken = 0; /* with 1 we'd always get success from list_files */
result = _rar_list_files(rar TSRMLS_CC);
rar->allow_broken = orig_allow_broken;

RETURN_BOOL(_rar_error_to_string(result) != NULL);
}
Expand Down Expand Up @@ -763,7 +764,7 @@ PHP_METHOD(rararch, __toString)
RAR_RETNULL_ON_ARGS();

if (_rar_get_file_resource_ex(arch_obj, &rar, TRUE TSRMLS_CC) == FAILURE) {
RETURN_FALSE;
RETURN_FALSE; /* should never happen */
}

is_closed = (rar->arch_handle == NULL);
Expand Down
12 changes: 12 additions & 0 deletions tests/005.phpt
Expand Up @@ -10,15 +10,27 @@ var_export(rar_comment_get($rar_file1));
echo "\n";
var_export(rar_comment_get($rar_file1));
echo "\n";
var_export($rar_file1->getComment());
echo "\n";

$rar_file2 = rar_open(dirname(__FILE__).'/linux_rar.rar');
var_export(rar_comment_get($rar_file2));
echo "\n";
rar_close($rar_file2);
var_export(rar_comment_get($rar_file2));
echo "\n";




echo "Done\n";
?>
--EXPECTF--
'This is the comment of the file commented.rar.'
'This is the comment of the file commented.rar.'
'This is the comment of the file commented.rar.'
NULL

Warning: rar_comment_get(): The archive is already closed in %s on line %d
false
Done
9 changes: 9 additions & 0 deletions tests/033.phpt
Expand Up @@ -8,8 +8,17 @@ $arch1 = RarArchive::open(dirname(__FILE__) . "/store_method.rar");
$arch2 = RarArchive::open(dirname(__FILE__) . "/solid.rar");
echo "$arch1: " . ($arch1->isSolid()?'yes':'no') ."\n";
echo "$arch2: " . (rar_solid_is($arch2)?'yes':'no') . "\n";

$arch2->close();
var_dump(rar_solid_is($arch2));

echo "\n";
echo "Done.\n";
--EXPECTF--
RAR Archive "%sstore_method.rar": no
RAR Archive "%ssolid.rar": yes

Warning: rar_solid_is(): The archive is already closed in %s on line %d
bool(false)

Done.
8 changes: 0 additions & 8 deletions tests/045.phpt
Expand Up @@ -66,8 +66,6 @@ Given callback that takes more arguments:

Warning: array_walk() expects at least %d parameters, 1 given in %s on line %d

Warning: RarArchive::getEntries(): Volume %smulti_broken.part2.rar was not found in %s on line %d

Warning: RarArchive::getEntries(): ERAR_EOPEN (file open error) in %s on line %d

Given callback that takes another kind of arguments:
Expand All @@ -76,24 +74,18 @@ Warning: ksort() expects parameter 1 to be array, string given in %s on line %d

Warning: RarArchive::getEntries(): Wrong type returned by volume find callback, expected string or NULL in %s on line %d

Warning: RarArchive::getEntries(): Volume %smulti_broken.part2.rar was not found in %s on line %d

Warning: RarArchive::getEntries(): ERAR_EOPEN (file open error) in %s on line %d

Given callback that returns another kind of arguments:

Warning: RarArchive::getEntries(): Wrong type returned by volume find callback, expected string or NULL in %s on line %d

Warning: RarArchive::getEntries(): Volume %smulti_broken.part2.rar was not found in %s on line %d

Warning: RarArchive::getEntries(): ERAR_EOPEN (file open error) in %s on line %d

Given callback that throws Exception:

Warning: RarArchive::getEntries(): Failure to call volume find callback in %s on line %d

Warning: RarArchive::getEntries(): Volume %smulti_broken.part2.rar was not found in %s on line %d

Warning: RarArchive::getEntries(): ERAR_EOPEN (file open error) in %s on line %d
OK, threw exception.
Done.
Expand Down
2 changes: 0 additions & 2 deletions tests/048.phpt
Expand Up @@ -22,7 +22,5 @@ echo "Done.\n";
--EXPECTF--
Warning: RarArchive::getEntries(): Cound not expand filename aaaa%s in %s on line %d

Warning: RarArchive::getEntries(): Volume %s was not found in %s on line %d

Warning: RarArchive::getEntries(): ERAR_EOPEN (file open error) in %s on line %d
Done.
2 changes: 2 additions & 0 deletions tests/083.phpt
Expand Up @@ -11,6 +11,7 @@ $a = RarArchive::open($f1);
echo "string (\"0\"). {$a['0']}\n";
echo "string (\"1abc\"). {$a['1abc']}\n";
echo "float (0.001). {$a[0.001]}\n";
echo "string (\"0.001\"). {$a['0.001']}\n";

echo "\n";
echo "Done.\n";
Expand All @@ -20,5 +21,6 @@ string ("0"). RarEntry for file "1.txt" (a0de71c0)
Notice: A non well formed numeric value encountered in %s on line %d
string ("1abc"). RarEntry for file "2.txt" (45a918de)
float (0.001). RarEntry for file "1.txt" (a0de71c0)
string ("0.001"). RarEntry for file "1.txt" (a0de71c0)

Done.
14 changes: 14 additions & 0 deletions tests/084.phpt
Expand Up @@ -34,6 +34,12 @@ echo $a["-18446744073709551616"];
echo "\n* 18446744073709551616 (float, 2^64):\n";
echo $a[(float) 18446744073709551616];

echo "\n* array():\n";
echo $a[array()];

echo "\n* new stdClass():\n";
echo $a[new stdClass()];

echo "\n";
echo "Done.\n";
--EXPECTF--
Expand Down Expand Up @@ -69,4 +75,12 @@ Warning: main(): Dimension index is out of integer bounds in %s on line %d

Warning: main(): Dimension index is out of integer bounds in %s on line %d

* array():

Warning: main(): Attempt to use a non-numeric dimension to access a RarArchive object (invalid type) in %s on line %d

* new stdClass():

Warning: main(): Attempt to use an object with no get handler as a dimension to access a RarArchive object in %s on line %d

Done.
62 changes: 5 additions & 57 deletions tests/085.phpt
@@ -1,72 +1,20 @@
--TEST--
RarArchive read_property handler invalid dimensions
RarArchive has_property handler is given a closed archive
--SKIPIF--
<?php if(!extension_loaded("rar")) print "skip"; ?>
--FILE--
<?php

//see also test #81 for broken archives

$f1 = dirname(__FILE__) . "/latest_winrar.rar";
$a = RarArchive::open($f1);
$a->close();

echo "* -1 (int):\n";
echo $a[-1];

echo "\n* -1 (string):\n";
echo $a["-1"];

echo "\n* -1 (double):\n";
echo $a[(float) -1];

echo "\n* 100:\n";
echo $a[100];

echo "\n* foo:\n";
echo $a["foo"];

echo "\n* 18446744073709551616 (string, 2^64):\n";
echo $a["18446744073709551616"];

echo "\n* -18446744073709551616 (string, -2^64):\n";
echo $a["-18446744073709551616"];

echo "\n* 18446744073709551616 (float, 2^64):\n";
echo $a[(float) 18446744073709551616];
var_dump(isset($a[0]));

echo "\n";
echo "Done.\n";
--EXPECTF--
* -1 (int):

Warning: main(): Dimension index must be non-negative, given -1 in %s on line %d

* -1 (string):

Warning: main(): Dimension index must be non-negative, given -1 in %s on line %d

* -1 (double):

Warning: main(): Dimension index must be non-negative, given -1 in %s on line %d

* 100:

Warning: main(): Dimension index exceeds or equals number of entries in RAR archive in %s on line %d

* foo:

Warning: main(): Attempt to use a non-numeric dimension to access a RarArchive object (invalid string) in %s on line %d

* 18446744073709551616 (string, 2^64):

Warning: main(): Dimension index is out of integer bounds in %s on line %d

* -18446744073709551616 (string, -2^64):

Warning: main(): Dimension index is out of integer bounds in %s on line %d

* 18446744073709551616 (float, 2^64):

Warning: main(): Dimension index is out of integer bounds in %s on line %d
Warning: main(): The archive is already closed in %s on line %d
bool(false)

Done.

0 comments on commit 9d49ce4

Please sign in to comment.