Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

- Fixed bug in dimensions handler.

- Added tests for read_dimensions handler.
- Methods/functions that receive no parameters enforce that.
- Added rar_is_broken and rar_allow_broken_set.

git-svn-id: http://svn.php.net/repository/pecl/rar/trunk@300009 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit 929b2526651e09250a1fadb5e3754b9360294a0a 1 parent 7bfe225
cataphract authored
2  extflow.txt
... ... @@ -1,3 +1,5 @@
  1 +(some information is outdated)
  2 +
1 3 rar_open/RarArchive::open()
2 4 gives
3 5 RarArchive object
30 php_rar.h
@@ -42,10 +42,9 @@
42 42 /* TODO: make configurable the capacity of the url_stater/dir_opener cache */
43 43 /* TODO: test url_stater/dir_opener cache exaustion */
44 44 /* TODO: optimize _rar_nav_directory_match with the depth */
45   -/* TODO: make RarArchive have dimensions */
46 45 /* TODO: tests with truncated RAR archive (for which _rar_list_files fails) */
47   -/* TODO: tests for dimensions stuff */
48   -/* TODO: allow dirty read of RAR files */
  46 +/* TODO: tests for allow broken RAR */
  47 +/* TODO: tests for has_property, write_property and [] */
49 48
50 49 #ifndef PHP_RAR_H
51 50 #define PHP_RAR_H
@@ -104,6 +103,18 @@ typedef struct rar {
104 103 int allow_broken;
105 104 } rar_file_t;
106 105
  106 +/* Misc */
  107 +#ifdef ZTS
  108 +# define RAR_TSRMLS_TC , void ***
  109 +#else
  110 +# define RAR_TSRMLS_TC
  111 +#endif
  112 +
  113 +#define RAR_RETNULL_ON_ARGS() \
  114 + if (zend_parse_parameters_none() == FAILURE) { \
  115 + RETURN_NULL(); \
  116 + }
  117 +
107 118 /* Per-request cache or make last the duration of the PHP lifespan?
108 119 * - per-request advantages: we can re-use rar_open and store close RarArchive
109 120 * objects. We store either pointers to the objects directly and manipulate
@@ -121,12 +132,6 @@ typedef struct rar {
121 132 * I'll also go with a FIFO eviction policy because it's simpler to implement
122 133 * (just delete the first element of the HashTable).
123 134 */
124   -#ifdef ZTS
125   -# define RAR_TSRMLS_TC , void ***
126   -#else
127   -# define RAR_TSRMLS_TC
128   -#endif
129   -
130 135 typedef struct _rar_contents_cache {
131 136 int max_size;
132 137 HashTable *data; //persistent HashTable, will hold rar_cache_entry
@@ -148,8 +153,11 @@ ZEND_EXTERN_MODULE_GLOBALS(rar);
148 153 # define RAR_G(v) (rar_globals.v)
149 154 #endif
150 155
151   -//PHP 5.2 compatibility
  156 +/* PHP 5.2 compatibility */
152 157 #if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3
  158 +#define zend_parse_parameters_none() \
  159 + zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "")
  160 +#define Z_DELREF_P ZVAL_DELREF
153 161 # define STREAM_ASSUME_REALPATH 0
154 162 # define ALLOC_PERMANENT_ZVAL(z) \
155 163 (z) = (zval*) malloc(sizeof(zval));
@@ -264,6 +272,8 @@ PHP_FUNCTION(rar_list);
264 272 PHP_FUNCTION(rar_entry_get);
265 273 PHP_FUNCTION(rar_solid_is);
266 274 PHP_FUNCTION(rar_comment_get);
  275 +PHP_FUNCTION(rar_broken_is);
  276 +PHP_FUNCTION(rar_allow_broken_set);
267 277 PHP_FUNCTION(rar_close);
268 278
269 279 /* rarentry.c */
23 rar.c
@@ -574,18 +574,29 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_rar_entry_get, 0, 0, 2)
574 574 #endif
575 575 ZEND_ARG_INFO(0, filename)
576 576 ZEND_END_ARG_INFO()
  577 +
  578 +ZEND_BEGIN_ARG_INFO_EX(arginfo_rar_allow_broken_set, 0, 0, 2)
  579 +#if 0 /* don't turn on type hinting yet */
  580 + ZEND_ARG_OBJ_INFO(0, rarfile, RarArchive, 0)
  581 +#else
  582 + ZEND_ARG_INFO(0, rarfile)
  583 +#endif
  584 + ZEND_ARG_INFO(0, allow_broken)
  585 +ZEND_END_ARG_INFO()
577 586 /* }}} */
578 587
579 588 /* {{{ rar_functions[]
580 589 *
581 590 */
582 591 static zend_function_entry rar_functions[] = {
583   - PHP_FE(rar_open, arginfo_rar_open)
584   - PHP_FE(rar_list, arginfo_rar_void_archmeth)
585   - PHP_FE(rar_entry_get, arginfo_rar_entry_get)
586   - PHP_FE(rar_solid_is, arginfo_rar_void_archmeth)
587   - PHP_FE(rar_comment_get, arginfo_rar_void_archmeth)
588   - PHP_FE(rar_close, arginfo_rar_void_archmeth)
  592 + PHP_FE(rar_open, arginfo_rar_open)
  593 + PHP_FE(rar_list, arginfo_rar_void_archmeth)
  594 + PHP_FE(rar_entry_get, arginfo_rar_entry_get)
  595 + PHP_FE(rar_solid_is, arginfo_rar_void_archmeth)
  596 + PHP_FE(rar_comment_get, arginfo_rar_void_archmeth)
  597 + PHP_FE(rar_broken_is, arginfo_rar_void_archmeth)
  598 + PHP_FE(rar_allow_broken_set, arginfo_rar_allow_broken_set)
  599 + PHP_FE(rar_close, arginfo_rar_void_archmeth)
589 600 {NULL, NULL, NULL}
590 601 };
591 602 /* }}} */
115 rararch.c
@@ -58,6 +58,19 @@ static zend_class_entry *rararch_ce_ptr;
58 58 static zend_object_handlers rararch_object_handlers;
59 59 /* }}} */
60 60
  61 +/* {{{ Helper macros */
  62 +#define RAR_THIS_OR_NO_ARGS(file) \
  63 + if (file == NULL) { \
  64 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", \
  65 + &file, rararch_ce_ptr) == FAILURE) { \
  66 + RETURN_NULL(); \
  67 + } \
  68 + } \
  69 + else { \
  70 + RAR_RETNULL_ON_ARGS(); \
  71 + }
  72 +/* }}} */
  73 +
61 74 /* {{{ Function prototypes for functions with internal linkage */
62 75 static zend_object_value rararch_ce_create_object(zend_class_entry *class_type TSRMLS_DC);
63 76 static void rararch_ce_destroy_object(ze_rararch_object *object,
@@ -444,6 +457,7 @@ static zval *rararch_read_dimension(zval *object, zval *offset, int type TSRMLS_
444 457 _rar_entry_to_zval(object, out->header, out->packed_size, out->position,
445 458 ret TSRMLS_CC);
446 459 _rar_entry_search_end(out);
  460 + Z_DELREF_P(ret); /* set refcount to 0 */
447 461 return ret;
448 462 }
449 463
@@ -543,10 +557,7 @@ PHP_FUNCTION(rar_list)
543 557 zval *file = getThis();
544 558 rar_file_t *rar = NULL;
545 559
546   - if (file == NULL && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O",
547   - &file, rararch_ce_ptr) == FAILURE) {
548   - return;
549   - }
  560 + RAR_THIS_OR_NO_ARGS(file);
550 561
551 562 if (_rar_get_file_resource(file, &rar TSRMLS_CC) == FAILURE) {
552 563 RETURN_FALSE;
@@ -574,15 +585,13 @@ PHP_FUNCTION(rar_entry_get)
574 585
575 586 if (file == NULL) {
576 587 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os",
577   - &file, rararch_ce_ptr, &filename, &filename_len) == FAILURE) {
  588 + &file, rararch_ce_ptr, &filename, &filename_len) == FAILURE) {
578 589 return;
579 590 }
580 591 }
581   - else {
582   - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
  592 + else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
583 593 &filename, &filename_len) == FAILURE) {
584   - return;
585   - }
  594 + return;
586 595 }
587 596
588 597 if (_rar_get_file_resource(file, &rar TSRMLS_CC) == FAILURE) {
@@ -620,10 +629,7 @@ PHP_FUNCTION(rar_solid_is)
620 629 zval *file = getThis();
621 630 rar_file_t *rar = NULL;
622 631
623   - if (file == NULL && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O",
624   - &file, rararch_ce_ptr) == FAILURE) {
625   - return;
626   - }
  632 + RAR_THIS_OR_NO_ARGS(file);
627 633
628 634 if (_rar_get_file_resource(file, &rar TSRMLS_CC) == FAILURE) {
629 635 RETURN_FALSE;
@@ -641,10 +647,7 @@ PHP_FUNCTION(rar_comment_get)
641 647 rar_file_t *rar = NULL;
642 648 unsigned cmt_state;
643 649
644   - if (file == NULL && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O",
645   - &file, rararch_ce_ptr) == FAILURE) {
646   - return;
647   - }
  650 + RAR_THIS_OR_NO_ARGS(file);
648 651
649 652 if (_rar_get_file_resource(file, &rar TSRMLS_CC) == FAILURE) {
650 653 RETURN_FALSE;
@@ -666,6 +669,53 @@ PHP_FUNCTION(rar_comment_get)
666 669 }
667 670 /* }}} */
668 671
  672 +/* {{{ proto bool rar_is_broken(RarArchive rarfile)
  673 + Check whether a RAR archive is broken */
  674 +PHP_FUNCTION(rar_broken_is)
  675 +{
  676 + zval *file = getThis();
  677 + rar_file_t *rar = NULL;
  678 + int result;
  679 +
  680 + RAR_THIS_OR_NO_ARGS(file);
  681 +
  682 + if (_rar_get_file_resource(file, &rar TSRMLS_CC) == FAILURE) {
  683 + RETURN_FALSE;
  684 + }
  685 +
  686 + result = _rar_list_files(rar TSRMLS_CC);
  687 +
  688 + RETURN_BOOL(_rar_error_to_string(result) != NULL);
  689 +}
  690 +
  691 +/* {{{ proto bool rar_allow_broken_set(RarArchive rarfile, bool allow_broken)
  692 + Whether to allow entry retrieval of broken RAR archives */
  693 +PHP_FUNCTION(rar_allow_broken_set)
  694 +{
  695 + zval *file = getThis();
  696 + rar_file_t *rar = NULL;
  697 + zend_bool allow_broken;
  698 +
  699 + if (file == NULL) {
  700 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ob",
  701 + &file, rararch_ce_ptr, &allow_broken) == FAILURE) {
  702 + return;
  703 + }
  704 + }
  705 + else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b",
  706 + &allow_broken) == FAILURE) {
  707 + return;
  708 + }
  709 +
  710 + if (_rar_get_file_resource(file, &rar TSRMLS_CC) == FAILURE) {
  711 + RETURN_FALSE;
  712 + }
  713 +
  714 + rar->allow_broken = (int) allow_broken;
  715 +
  716 + RETURN_TRUE;
  717 +}
  718 +
669 719 /* {{{ proto bool rar_close(RarArchive rarfile)
670 720 Close Rar archive and free all resources */
671 721 PHP_FUNCTION(rar_close)
@@ -673,10 +723,7 @@ PHP_FUNCTION(rar_close)
673 723 zval *file = getThis();
674 724 rar_file_t *rar = NULL;
675 725
676   - if (file == NULL && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O",
677   - &file, rararch_ce_ptr) == FAILURE) {
678   - return;
679   - }
  726 + RAR_THIS_OR_NO_ARGS(file);
680 727
681 728 if (_rar_get_file_resource(file, &rar TSRMLS_CC) == FAILURE) {
682 729 RETURN_FALSE;
@@ -699,6 +746,8 @@ PHP_METHOD(rararch, __toString)
699 746 char *restring;
700 747 size_t restring_size;
701 748 int is_closed;
  749 +
  750 + RAR_RETNULL_ON_ARGS();
702 751
703 752 if (_rar_get_file_resource_ex(arch_obj, &rar, TRUE TSRMLS_CC) == FAILURE) {
704 753 RETURN_FALSE;
@@ -732,22 +781,28 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_rararchive_getentry, 0, 0, 1)
732 781 ZEND_ARG_INFO(0, filename)
733 782 ZEND_END_ARG_INFO()
734 783
  784 +ZEND_BEGIN_ARG_INFO_EX(arginfo_rararchive_setallowbroken, 0, 0, 1)
  785 + ZEND_ARG_INFO(0, allow_broken)
  786 +ZEND_END_ARG_INFO()
  787 +
735 788 ZEND_BEGIN_ARG_INFO(arginfo_rararchive_void, 0)
736 789 ZEND_END_ARG_INFO()
737 790 /* }}} */
738 791
739 792 static zend_function_entry php_rararch_class_functions[] = {
740   - PHP_ME_MAPPING(open, rar_open, arginfo_rararchive_open, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
741   - PHP_ME_MAPPING(getEntries, rar_list, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
742   - PHP_ME_MAPPING(getEntry, rar_entry_get, arginfo_rararchive_getentry, ZEND_ACC_PUBLIC)
  793 + PHP_ME_MAPPING(open, rar_open, arginfo_rararchive_open, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
  794 + PHP_ME_MAPPING(getEntries, rar_list, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
  795 + PHP_ME_MAPPING(getEntry, rar_entry_get, arginfo_rararchive_getentry, ZEND_ACC_PUBLIC)
743 796 #ifdef RAR_ARCHIVE_LIST_ALIAS
744   - PHP_ME_MAPPING(list, rar_list, arginfo_rararchive_void, ZEND_ACC_PUBLIC | ZEND_ACC_DEPRECATED)
  797 + PHP_ME_MAPPING(list, rar_list, arginfo_rararchive_void, ZEND_ACC_PUBLIC | ZEND_ACC_DEPRECATED)
745 798 #endif
746   - PHP_ME_MAPPING(isSolid, rar_solid_is, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
747   - PHP_ME_MAPPING(getComment, rar_comment_get, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
748   - PHP_ME_MAPPING(close, rar_close, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
749   - PHP_ME(rararch, __toString, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
750   - PHP_ME_MAPPING(__construct, rar_bogus_ctor, arginfo_rararchive_void, ZEND_ACC_PRIVATE | ZEND_ACC_CTOR)
  799 + PHP_ME_MAPPING(isSolid, rar_solid_is, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
  800 + PHP_ME_MAPPING(getComment, rar_comment_get, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
  801 + PHP_ME_MAPPING(isBroken, rar_broken_is, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
  802 + PHP_ME_MAPPING(setAllowBroken, rar_allow_broken_set, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
  803 + PHP_ME_MAPPING(close, rar_close, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
  804 + PHP_ME(rararch, __toString, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
  805 + PHP_ME_MAPPING(__construct, rar_bogus_ctor, arginfo_rararchive_void, ZEND_ACC_PRIVATE | ZEND_ACC_CTOR)
751 806 {NULL, NULL, NULL}
752 807 };
753 808
26 rarentry.c
@@ -354,6 +354,8 @@ PHP_METHOD(rarentry, getPosition)
354 354 {
355 355 zval **tmp;
356 356 zval *entry_obj = getThis();
  357 +
  358 + RAR_RETNULL_ON_ARGS();
357 359
358 360 RAR_GET_PROPERTY(tmp, "position");
359 361
@@ -367,6 +369,8 @@ PHP_METHOD(rarentry, getName)
367 369 {
368 370 zval **tmp;
369 371 zval *entry_obj = getThis();
  372 +
  373 + RAR_RETNULL_ON_ARGS();
370 374
371 375 RAR_GET_PROPERTY(tmp, "name");
372 376
@@ -381,6 +385,8 @@ PHP_METHOD(rarentry, getUnpackedSize)
381 385 zval **tmp;
382 386 zval *entry_obj = getThis();
383 387
  388 + RAR_RETNULL_ON_ARGS();
  389 +
384 390 RAR_GET_PROPERTY(tmp, "unpacked_size");
385 391
386 392 RETURN_LONG(Z_LVAL_PP(tmp));
@@ -393,6 +399,8 @@ PHP_METHOD(rarentry, getPackedSize)
393 399 {
394 400 zval **tmp;
395 401 zval *entry_obj = getThis();
  402 +
  403 + RAR_RETNULL_ON_ARGS();
396 404
397 405 RAR_GET_PROPERTY(tmp, "packed_size");
398 406
@@ -406,6 +414,8 @@ PHP_METHOD(rarentry, getHostOs)
406 414 {
407 415 zval **tmp;
408 416 zval *entry_obj = getThis();
  417 +
  418 + RAR_RETNULL_ON_ARGS();
409 419
410 420 RAR_GET_PROPERTY(tmp, "host_os");
411 421
@@ -419,6 +429,8 @@ PHP_METHOD(rarentry, getFileTime)
419 429 {
420 430 zval **tmp;
421 431 zval *entry_obj = getThis();
  432 +
  433 + RAR_RETNULL_ON_ARGS();
422 434
423 435 RAR_GET_PROPERTY(tmp, "file_time");
424 436
@@ -432,6 +444,8 @@ PHP_METHOD(rarentry, getCrc)
432 444 {
433 445 zval **tmp;
434 446 zval *entry_obj = getThis();
  447 +
  448 + RAR_RETNULL_ON_ARGS();
435 449
436 450 RAR_GET_PROPERTY(tmp, "crc");
437 451
@@ -445,6 +459,8 @@ PHP_METHOD(rarentry, getAttr)
445 459 {
446 460 zval **tmp;
447 461 zval *entry_obj = getThis();
  462 +
  463 + RAR_RETNULL_ON_ARGS();
448 464
449 465 RAR_GET_PROPERTY(tmp, "attr");
450 466
@@ -458,6 +474,8 @@ PHP_METHOD(rarentry, getVersion)
458 474 {
459 475 zval **tmp;
460 476 zval *entry_obj = getThis();
  477 +
  478 + RAR_RETNULL_ON_ARGS();
461 479
462 480 RAR_GET_PROPERTY(tmp, "version");
463 481
@@ -471,6 +489,8 @@ PHP_METHOD(rarentry, getMethod)
471 489 {
472 490 zval **tmp;
473 491 zval *entry_obj = getThis();
  492 +
  493 + RAR_RETNULL_ON_ARGS();
474 494
475 495 RAR_GET_PROPERTY(tmp, "method");
476 496
@@ -528,6 +548,8 @@ PHP_METHOD(rarentry, isDirectory)
528 548 zval *entry_obj = getThis();
529 549 long flags;
530 550 int is_dir;
  551 +
  552 + RAR_RETNULL_ON_ARGS();
531 553
532 554 RAR_GET_PROPERTY(tmp, "flags");
533 555 flags = Z_LVAL_PP(tmp);
@@ -545,6 +567,8 @@ PHP_METHOD(rarentry, isEncrypted)
545 567 zval *entry_obj = getThis();
546 568 long flags;
547 569 int is_encrypted;
  570 +
  571 + RAR_RETNULL_ON_ARGS();
548 572
549 573 RAR_GET_PROPERTY(tmp, "flags");
550 574 flags = Z_LVAL_PP(tmp);
@@ -569,6 +593,8 @@ PHP_METHOD(rarentry, __toString)
569 593 char *restring;
570 594 int restring_len;
571 595 const char format[] = "RarEntry for %s \"%s\" (%s)";
  596 +
  597 + RAR_RETNULL_ON_ARGS();
572 598
573 599 RAR_GET_PROPERTY(flags_zval, "flags");
574 600 flags = Z_LVAL_PP(flags_zval);
36 tests/082.phpt
... ... @@ -0,0 +1,36 @@
  1 +--TEST--
  2 +RarArchive read_property handler basic test
  3 +--SKIPIF--
  4 +<?php if(!extension_loaded("rar")) print "skip"; ?>
  5 +--FILE--
  6 +<?php
  7 +
  8 +//see also test #81 for broken archives
  9 +
  10 +$f1 = dirname(__FILE__) . "/latest_winrar.rar";
  11 +$f2 = dirname(__FILE__) . "/multi.part1.rar";
  12 +
  13 +echo "* latest_winrar.rar:\n";
  14 +$a = RarArchive::open($f1);
  15 +for ($i = 0; $i < 2; $i++) {
  16 + echo ($i + 1) . ". $a[$i]\n";
  17 +}
  18 +
  19 +echo "\n* multi.part1.rar:\n";
  20 +$a = RarArchive::open($f2);
  21 +for ($i = 0; $i < 2; $i++) {
  22 + echo ($i + 1) . ". $a[$i]\n";
  23 +}
  24 +
  25 +echo "\n";
  26 +echo "Done.\n";
  27 +--EXPECTF--
  28 +* latest_winrar.rar:
  29 +1. RarEntry for file "1.txt" (a0de71c0)
  30 +2. RarEntry for file "2.txt" (45a918de)
  31 +
  32 +* multi.part1.rar:
  33 +1. RarEntry for file "file1.txt" (52b28202)
  34 +2. RarEntry for file "file2.txt" (f2c79881)
  35 +
  36 +Done.
24 tests/083.phpt
... ... @@ -0,0 +1,24 @@
  1 +--TEST--
  2 +RarArchive read_property handler non-int valid dimensions
  3 +--SKIPIF--
  4 +<?php if(!extension_loaded("rar")) print "skip"; ?>
  5 +--FILE--
  6 +<?php
  7 +
  8 +$f1 = dirname(__FILE__) . "/latest_winrar.rar";
  9 +$a = RarArchive::open($f1);
  10 +
  11 +echo "string (\"0\"). {$a['0']}\n";
  12 +echo "string (\"1abc\"). {$a['1abc']}\n";
  13 +echo "float (0.001). {$a[0.001]}\n";
  14 +
  15 +echo "\n";
  16 +echo "Done.\n";
  17 +--EXPECTF--
  18 +string ("0"). RarEntry for file "1.txt" (a0de71c0)
  19 +
  20 +Notice: A non well formed numeric value encountered in %s on line %d
  21 +string ("1abc"). RarEntry for file "2.txt" (45a918de)
  22 +float (0.001). RarEntry for file "1.txt" (a0de71c0)
  23 +
  24 +Done.
72 tests/084.phpt
... ... @@ -0,0 +1,72 @@
  1 +--TEST--
  2 +RarArchive read_property handler invalid dimensions
  3 +--SKIPIF--
  4 +<?php if(!extension_loaded("rar")) print "skip"; ?>
  5 +--FILE--
  6 +<?php
  7 +
  8 +//see also test #81 for broken archives
  9 +
  10 +$f1 = dirname(__FILE__) . "/latest_winrar.rar";
  11 +$a = RarArchive::open($f1);
  12 +
  13 +echo "* -1 (int):\n";
  14 +echo $a[-1];
  15 +
  16 +echo "\n* -1 (string):\n";
  17 +echo $a["-1"];
  18 +
  19 +echo "\n* -1 (double):\n";
  20 +echo $a[(float) -1];
  21 +
  22 +echo "\n* 100:\n";
  23 +echo $a[100];
  24 +
  25 +echo "\n* foo:\n";
  26 +echo $a["foo"];
  27 +
  28 +echo "\n* 18446744073709551616 (string, 2^64):\n";
  29 +echo $a["18446744073709551616"];
  30 +
  31 +echo "\n* -18446744073709551616 (string, -2^64):\n";
  32 +echo $a["-18446744073709551616"];
  33 +
  34 +echo "\n* 18446744073709551616 (float, 2^64):\n";
  35 +echo $a[(float) 18446744073709551616];
  36 +
  37 +echo "\n";
  38 +echo "Done.\n";
  39 +--EXPECTF--
  40 +* -1 (int):
  41 +
  42 +Warning: main(): Dimension index must be non-negative, given -1 in %s on line %d
  43 +
  44 +* -1 (string):
  45 +
  46 +Warning: main(): Dimension index must be non-negative, given -1 in %s on line %d
  47 +
  48 +* -1 (double):
  49 +
  50 +Warning: main(): Dimension index must be non-negative, given -1 in %s on line %d
  51 +
  52 +* 100:
  53 +
  54 +Warning: main(): Dimension index exceeds or equals number of entries in RAR archive in %s on line %d
  55 +
  56 +* foo:
  57 +
  58 +Warning: main(): Attempt to use a non-numeric dimension to access a RarArchive object (invalid string) in %s on line %d
  59 +
  60 +* 18446744073709551616 (string, 2^64):
  61 +
  62 +Warning: main(): Dimension index is out of integer bounds in %s on line %d
  63 +
  64 +* -18446744073709551616 (string, -2^64):
  65 +
  66 +Warning: main(): Dimension index is out of integer bounds in %s on line %d
  67 +
  68 +* 18446744073709551616 (float, 2^64):
  69 +
  70 +Warning: main(): Dimension index is out of integer bounds in %s on line %d
  71 +
  72 +Done.
72 tests/085.phpt
... ... @@ -0,0 +1,72 @@
  1 +--TEST--
  2 +RarArchive read_property handler invalid dimensions
  3 +--SKIPIF--
  4 +<?php if(!extension_loaded("rar")) print "skip"; ?>
  5 +--FILE--
  6 +<?php
  7 +
  8 +//see also test #81 for broken archives
  9 +
  10 +$f1 = dirname(__FILE__) . "/latest_winrar.rar";
  11 +$a = RarArchive::open($f1);
  12 +
  13 +echo "* -1 (int):\n";
  14 +echo $a[-1];
  15 +
  16 +echo "\n* -1 (string):\n";
  17 +echo $a["-1"];
  18 +
  19 +echo "\n* -1 (double):\n";
  20 +echo $a[(float) -1];
  21 +
  22 +echo "\n* 100:\n";
  23 +echo $a[100];
  24 +
  25 +echo "\n* foo:\n";
  26 +echo $a["foo"];
  27 +
  28 +echo "\n* 18446744073709551616 (string, 2^64):\n";
  29 +echo $a["18446744073709551616"];
  30 +
  31 +echo "\n* -18446744073709551616 (string, -2^64):\n";
  32 +echo $a["-18446744073709551616"];
  33 +
  34 +echo "\n* 18446744073709551616 (float, 2^64):\n";
  35 +echo $a[(float) 18446744073709551616];
  36 +
  37 +echo "\n";
  38 +echo "Done.\n";
  39 +--EXPECTF--
  40 +* -1 (int):
  41 +
  42 +Warning: main(): Dimension index must be non-negative, given -1 in %s on line %d
  43 +
  44 +* -1 (string):
  45 +
  46 +Warning: main(): Dimension index must be non-negative, given -1 in %s on line %d
  47 +
  48 +* -1 (double):
  49 +
  50 +Warning: main(): Dimension index must be non-negative, given -1 in %s on line %d
  51 +
  52 +* 100:
  53 +
  54 +Warning: main(): Dimension index exceeds or equals number of entries in RAR archive in %s on line %d
  55 +
  56 +* foo:
  57 +
  58 +Warning: main(): Attempt to use a non-numeric dimension to access a RarArchive object (invalid string) in %s on line %d
  59 +
  60 +* 18446744073709551616 (string, 2^64):
  61 +
  62 +Warning: main(): Dimension index is out of integer bounds in %s on line %d
  63 +
  64 +* -18446744073709551616 (string, -2^64):
  65 +
  66 +Warning: main(): Dimension index is out of integer bounds in %s on line %d
  67 +
  68 +* 18446744073709551616 (float, 2^64):
  69 +
  70 +Warning: main(): Dimension index is out of integer bounds in %s on line %d
  71 +
  72 +Done.

0 comments on commit 929b252

Please sign in to comment.
Something went wrong with that request. Please try again.