File tree Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -618,10 +618,13 @@ static inline void phar_set_inode(phar_entry_info *entry TSRMLS_DC) /* {{{ */
618
618
{
619
619
char tmp [MAXPATHLEN ];
620
620
int tmp_len ;
621
+ size_t len ;
621
622
622
- tmp_len = entry -> filename_len + entry -> phar -> fname_len ;
623
- memcpy (tmp , entry -> phar -> fname , entry -> phar -> fname_len );
624
- memcpy (tmp + entry -> phar -> fname_len , entry -> filename , entry -> filename_len );
623
+ tmp_len = MIN (MAXPATHLEN , entry -> filename_len + entry -> phar -> fname_len );
624
+ len = MIN (entry -> phar -> fname_len , tmp_len );
625
+ memcpy (tmp , entry -> phar -> fname , len );
626
+ len = MIN (tmp_len - len , entry -> filename_len );
627
+ memcpy (tmp + entry -> phar -> fname_len , entry -> filename , len );
625
628
entry -> inode = (unsigned short )zend_get_hash_value (tmp , tmp_len );
626
629
}
627
630
/* }}} */
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Phar: bug #69441: Buffer Overflow when parsing tar/zip/phar in phar_set_inode
3
+ --SKIPIF--
4
+ <?php if (!extension_loaded ("phar " )) die ("skip " ); ?>
5
+ --FILE--
6
+ <?php
7
+ $ fname = dirname (__FILE__ ) . '/bug69441.phar ' ;
8
+ try {
9
+ $ r = new Phar ($ fname , 0 );
10
+ } catch (UnexpectedValueException $ e ) {
11
+ echo $ e ;
12
+ }
13
+ ?>
14
+
15
+ ==DONE==
16
+ --EXPECTF--
17
+ exception 'UnexpectedValueException' with message 'phar error: corrupted central directory entry, no magic signature in zip-based phar "%s/bug69441.phar"' in %s/bug69441.php:%d
18
+ Stack trace:
19
+ #0 %s/bug69441.php(%d): Phar->__construct('%s', 0)
20
+ #1 {main}
21
+ ==DONE==
You can’t perform that action at this time.
0 commit comments